[Core] Allow listening for mutation

Allow listeners to register with a domain object's
mutation capability to detect changes to that
domain object. Allows other components to respond
to these changes without resorting to polling on
timestamp or similar. WTD-1329.
This commit is contained in:
Victor Woeltjen
2015-06-24 10:20:49 -07:00
parent 47647f4ada
commit c668fa041a
2 changed files with 49 additions and 3 deletions

View File

@@ -83,6 +83,26 @@ define(
// Should have gotten a timestamp from 'now'
expect(testModel.modified).toEqual(42);
});
it("notifies listeners of mutation", function () {
var mockCallback = jasmine.createSpy('callback');
mutation.listen(mockCallback);
mutation.invoke(function (m) {
m.number = 8;
});
expect(mockCallback).toHaveBeenCalled();
expect(mockCallback.mostRecentCall.args[0].number)
.toEqual(8);
});
it("allows listeners to stop listening", function () {
var mockCallback = jasmine.createSpy('callback');
mutation.listen(mockCallback)(); // Unlisten immediately
mutation.invoke(function (m) {
m.number = 8;
});
expect(mockCallback).not.toHaveBeenCalled();
});
});
}
);
);