[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:
@@ -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();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user