Mutation API (#1074)

* [API] Allow selection

* [API] Keep in sync using model

* [API] Add selection as EventEmitter

* [API] Use selection from ToDo tutorial

* Object events prototype

* Added examples

* Transitional API

* Modified todo list code to work with new setters

* [API] Removed emitting of events on container when property changes value to remove ambiguity. Listeners must be listening to the same path used in the setter to catch changes
This commit is contained in:
Andrew Henry
2016-07-07 14:30:45 -07:00
committed by Pete Richards
parent d7ddb96c4e
commit 1879c122c7
8 changed files with 324 additions and 69 deletions

View File

@ -5,6 +5,7 @@ define([
'./api/api',
'text!./adapter/templates/edit-object-replacement.html',
'./ui/Dialog',
'./Selection',
'./api/objects/bundle'
], function (
EventEmitter,
@ -12,11 +13,15 @@ define([
uuid,
api,
editObjectTemplate,
Dialog
Dialog,
Selection
) {
function MCT() {
EventEmitter.call(this);
this.legacyBundle = { extensions: {} };
this.selection = new Selection();
this.on('navigation', this.selection.clear.bind(this.selection));
}
MCT.prototype = Object.create(EventEmitter.prototype);
@ -91,6 +96,14 @@ define([
};
MCT.prototype.start = function () {
this.legacyExtension('runs', {
depends: ['navigationService'],
implementation: function (navigationService) {
navigationService
.addListener(this.emit.bind(this, 'navigation'));
}.bind(this)
});
legacyRegistry.register('adapter', this.legacyBundle);
this.emit('start');
};
@ -100,19 +113,5 @@ define([
toolbar: "TOOLBAR"
};
MCT.prototype.verbs = {
mutate: function (domainObject, mutator) {
return domainObject.useCapability('mutation', mutator)
.then(function () {
var persistence = domainObject.getCapability('persistence');
return persistence.persist();
});
},
observe: function (domainObject, callback) {
var mutation = domainObject.getCapability('mutation');
return mutation.listen(callback);
}
};
return MCT;
});