Watch properties cancel long poll requests

This commit is contained in:
Michael Lange
2018-02-14 15:41:07 -08:00
parent ed809fe27e
commit b69fe312b8

View File

@@ -18,27 +18,35 @@ export function watchRecord(modelName) {
} catch (e) {
yield e;
break;
} finally {
this.get('store')
.adapterFor(modelName)
.cancelFindRecord(modelName, id);
}
}
});
}).drop();
}
export function watchRelationship(staticRelationshipName) {
export function watchRelationship(relationshipName) {
return task(function*(model, throttle = 2000) {
while (true) {
try {
yield RSVP.all([
this.get('store')
.adapterFor(model.constructor.modelName)
.reloadRelationship(model, staticRelationshipName, true),
.reloadRelationship(model, relationshipName, true),
wait(throttle),
]);
} catch (e) {
yield e;
break;
} finally {
this.get('store')
.adapterFor(model.constructor.name)
.cancelReloadRelationship(model, relationshipName);
}
}
});
}).drop();
}
export function watchAll(modelName) {
@@ -52,7 +60,11 @@ export function watchAll(modelName) {
} catch (e) {
yield e;
break;
} finally {
this.get('store')
.adapterFor(modelName)
.cancelFindAll(modelName);
}
}
});
}).drop();
}