[WIP] Get rid of parameters sifting
Change-Id: Ie9185c1abfd4edcc0b9e4920fa674e75718b6222
This commit is contained in:
parent
5cbbc51b35
commit
b1df00f01a
|
@ -131,11 +131,12 @@
|
||||||
'@type': Object,
|
'@type': Object,
|
||||||
'base': {
|
'base': {
|
||||||
'@class': fields.linkedcollection.extend({
|
'@class': fields.linkedcollection.extend({
|
||||||
create: function(json, parameters) {
|
create: function(json) {
|
||||||
parameters = Object.create(parameters);
|
var parameters = {
|
||||||
parameters.toCls = models.StandardActions;
|
toCls: models.StandardActions,
|
||||||
parameters.neededCls = models.Root;
|
neededCls: models.Root,
|
||||||
parameters.substitutedEntryID = 'standardActions';
|
substitutedEntryID: 'standardActions'
|
||||||
|
};
|
||||||
return fields.linkedcollection.create.call(this, json, parameters);
|
return fields.linkedcollection.create.call(this, json, parameters);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
@ -360,11 +361,12 @@
|
||||||
return this.extend({}, {
|
return this.extend({}, {
|
||||||
'action': {
|
'action': {
|
||||||
'@class': fields.linkedcollection.extend({
|
'@class': fields.linkedcollection.extend({
|
||||||
create: function(json, parameters) {
|
create: function(json) {
|
||||||
parameters = Object.create(parameters);
|
var parameters = {
|
||||||
parameters.toCls = models.Actions;
|
toCls: models.Actions,
|
||||||
parameters.neededCls = models.Workbook;
|
neededCls: models.Workbook,
|
||||||
parameters.substitutedEntryID = 'actions';
|
substitutedEntryID: 'actions'
|
||||||
|
};
|
||||||
return fields.linkedcollection.create.call(this, json, parameters);
|
return fields.linkedcollection.create.call(this, json, parameters);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
@ -380,11 +382,12 @@
|
||||||
return this.extend({}, {
|
return this.extend({}, {
|
||||||
'workflow': {
|
'workflow': {
|
||||||
'@class': fields.linkedcollection.extend({
|
'@class': fields.linkedcollection.extend({
|
||||||
create: function(json, parameters) {
|
create: function(json) {
|
||||||
parameters = Object.create(parameters);
|
var parameters = {
|
||||||
parameters.toCls = models.Workflows;
|
toCls: models.Workflows,
|
||||||
parameters.neededCls = models.Workbook;
|
neededCls: models.Workbook,
|
||||||
parameters.substitutedEntryID = 'workflows';
|
substitutedEntryID: 'workflows'
|
||||||
|
};
|
||||||
return fields.linkedcollection.create.call(this, json, parameters);
|
return fields.linkedcollection.create.call(this, json, parameters);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
@ -403,12 +406,28 @@
|
||||||
'workflow': models.WorkflowTaskMixin
|
'workflow': models.WorkflowTaskMixin
|
||||||
};
|
};
|
||||||
|
|
||||||
function TaskFactory(json, parameters) {
|
function TaskFactoryFactory(baseClass) {
|
||||||
var type = json.type || 'action';
|
return function TaskFactory(json, parameters) {
|
||||||
var baseClass = taskTypes[parameters.wfType];
|
var type = json.type || 'action';
|
||||||
var mixinClass = taskTypes[type];
|
var mixinClass = taskTypes[type];
|
||||||
var taskClass = mixinClass.call(baseClass);
|
var taskClass = mixinClass.call(baseClass);
|
||||||
return taskClass.create(json, parameters);
|
return taskClass.create(json, parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createTaskFactory(baseClass) {
|
||||||
|
return function(json, parameters) {
|
||||||
|
var self = Barricade.MutableObject.create.call(this, json, parameters);
|
||||||
|
self.on('childChange', function(child, op) {
|
||||||
|
if ( op === 'taskType' ) {
|
||||||
|
var taskId = child.getID();
|
||||||
|
var taskPos = self.getPosByID(taskId);
|
||||||
|
var taskData = child.toJSON();
|
||||||
|
self.set(taskPos, TaskFactoryFactory(baseClass)(taskData, {id: taskId}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return self;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
models.Workflow = Barricade.ImmutableObject.extend({
|
models.Workflow = Barricade.ImmutableObject.extend({
|
||||||
|
@ -450,23 +469,13 @@
|
||||||
'*': {
|
'*': {
|
||||||
'@type': String
|
'@type': String
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
models.ReverseWorkflow = models.Workflow.extend({}, {
|
||||||
'tasks': {
|
'tasks': {
|
||||||
'@class': Barricade.MutableObject.extend({
|
'@class': Barricade.MutableObject.extend({
|
||||||
create: function(json, parameters) {
|
create: createTaskFactory(models.ReverseWFTask)
|
||||||
var self = Barricade.MutableObject.create.call(this, json, parameters);
|
|
||||||
self.on('childChange', function(child, op, arg) {
|
|
||||||
if ( op === 'taskType' ) {
|
|
||||||
var taskId = child.getID();
|
|
||||||
var params = child._parameters;
|
|
||||||
var taskPos = self.getPosByID(taskId);
|
|
||||||
var taskData = child.toJSON();
|
|
||||||
params.id = taskId;
|
|
||||||
self.set(taskPos, TaskFactory(taskData, params));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
}, {
|
}, {
|
||||||
'@type': Object,
|
'@type': Object,
|
||||||
'@meta': {
|
'@meta': {
|
||||||
|
@ -474,14 +483,11 @@
|
||||||
},
|
},
|
||||||
'?': {
|
'?': {
|
||||||
'@class': models.Task,
|
'@class': models.Task,
|
||||||
'@factory': TaskFactory
|
'@factory': TaskFactoryFactory(models.ReverseWFTask)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
models.ReverseWorkflow = models.Workflow.extend({});
|
|
||||||
models.DirectWorkflow = models.Workflow.extend({}, {
|
models.DirectWorkflow = models.Workflow.extend({}, {
|
||||||
'task-defaults': {
|
'task-defaults': {
|
||||||
'@type': Object,
|
'@type': Object,
|
||||||
|
@ -513,7 +519,20 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
'tasks': {
|
||||||
|
'@class': Barricade.MutableObject.extend({
|
||||||
|
create: createTaskFactory(models.DirectWFTask)
|
||||||
|
}, {
|
||||||
|
'@type': Object,
|
||||||
|
'@meta': {
|
||||||
|
'index': 5
|
||||||
|
},
|
||||||
|
'?': {
|
||||||
|
'@class': models.Task,
|
||||||
|
'@factory': TaskFactoryFactory(models.DirectWFTask)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -524,7 +543,6 @@
|
||||||
|
|
||||||
function workflowFactory(json, parameters) {
|
function workflowFactory(json, parameters) {
|
||||||
var type = json.type || 'direct';
|
var type = json.type || 'direct';
|
||||||
parameters.wfType = type;
|
|
||||||
return workflowTypes[type].create(json, parameters);
|
return workflowTypes[type].create(json, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -546,11 +564,8 @@
|
||||||
if ( op === 'workflowType' ) {
|
if ( op === 'workflowType' ) {
|
||||||
var workflowId = child.getID();
|
var workflowId = child.getID();
|
||||||
var workflowPos = self.getPosByID(workflowId);
|
var workflowPos = self.getPosByID(workflowId);
|
||||||
var params = child._parameters;
|
|
||||||
var workflowData = child.toJSON();
|
var workflowData = child.toJSON();
|
||||||
params.wfType = child.type;
|
self.set(workflowPos, workflowFactory(workflowData, {id: workflowId}));
|
||||||
params.id = workflowId;
|
|
||||||
self.set(workflowPos, workflowFactory(workflowData, params));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return self;
|
return self;
|
||||||
|
|
|
@ -261,78 +261,55 @@ var Barricade = (function () {
|
||||||
* @mixin
|
* @mixin
|
||||||
* @memberof Barricade
|
* @memberof Barricade
|
||||||
*/
|
*/
|
||||||
Deferrable = Blueprint.create(function () {
|
Deferrable = Blueprint.create(function (schema) {
|
||||||
var existingCreate = this.create;
|
var self = this,
|
||||||
|
needed,
|
||||||
|
deferred = schema.hasOwnProperty('@ref')
|
||||||
|
? Deferred.create(schema['@ref'].needs, getter, resolver)
|
||||||
|
: null;
|
||||||
|
|
||||||
this.create = function() {
|
if (schema.hasOwnProperty('@ref') && !schema['@ref'].processor) {
|
||||||
var self = existingCreate.apply(this, arguments),
|
schema['@ref'].processor = function (o) { return o.val; };
|
||||||
schema = self._schema,
|
}
|
||||||
needed,
|
|
||||||
deferred = schema.hasOwnProperty('@ref')
|
|
||||||
? Deferred.create(schema['@ref'].needs, getter, resolver)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (schema.hasOwnProperty('@ref') && !schema['@ref'].processor) {
|
function getter(neededVal) {
|
||||||
schema['@ref'].processor = function (o) { return o.val; };
|
return schema['@ref'].getter({standIn: self, needed: neededVal});
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolver(retrievedValue) {
|
||||||
|
self.emit('replace', schema['@ref'].processor({
|
||||||
|
val: retrievedValue,
|
||||||
|
standIn: self,
|
||||||
|
needed: needed
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.resolveWith = function (obj) {
|
||||||
|
var allResolved = true;
|
||||||
|
|
||||||
|
if (deferred && !deferred.isResolved()) {
|
||||||
|
if (deferred.needs(obj)) {
|
||||||
|
needed = obj;
|
||||||
|
deferred.resolve(obj);
|
||||||
|
} else {
|
||||||
|
allResolved = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getter(neededVal) {
|
if (this.instanceof(Container)) {
|
||||||
return schema['@ref'].getter(
|
this.each(function (index, value) {
|
||||||
{standIn: self, needed: neededVal});
|
if (!value.resolveWith(obj)) {
|
||||||
}
|
|
||||||
|
|
||||||
function resolver(retrievedValue) {
|
|
||||||
self.emit('replace', schema['@ref'].processor({
|
|
||||||
val: retrievedValue,
|
|
||||||
standIn: self,
|
|
||||||
needed: needed
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.resolveWith = function (obj) {
|
|
||||||
var allResolved = true;
|
|
||||||
|
|
||||||
if (deferred && !deferred.isResolved()) {
|
|
||||||
if (deferred.needs(obj)) {
|
|
||||||
needed = obj;
|
|
||||||
deferred.resolve(obj);
|
|
||||||
} else {
|
|
||||||
allResolved = false;
|
allResolved = false;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (this.instanceof(Container)) {
|
return allResolved;
|
||||||
this.each(function (index, value) {
|
|
||||||
if (!value.resolveWith(obj)) {
|
|
||||||
allResolved = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return allResolved;
|
|
||||||
};
|
|
||||||
|
|
||||||
self.isPlaceholder = function () {
|
|
||||||
return !!deferred;
|
|
||||||
};
|
|
||||||
|
|
||||||
return self;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.isValidRef = function(instance) {
|
this.isPlaceholder = function () {
|
||||||
var clsRef = this._schema['@ref'];
|
return !!deferred;
|
||||||
if (!clsRef) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (typeof clsRef.to === 'function') {
|
|
||||||
return this._safeInstanceof(instance, clsRef.to());
|
|
||||||
} else if (typeof clsRef.to === 'object') {
|
|
||||||
return this._safeInstanceof(instance, clsRef.to);
|
|
||||||
}
|
|
||||||
throw new Error('Ref.to was ' + clsRef.to);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return this;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -581,7 +558,7 @@ var Barricade = (function () {
|
||||||
* @mixes Barricade.Identifiable
|
* @mixes Barricade.Identifiable
|
||||||
* @extends Barricade.Identifiable
|
* @extends Barricade.Identifiable
|
||||||
*/
|
*/
|
||||||
Base = Deferrable.call(Extendable.call(InstanceofMixin.call({
|
Base = Extendable.call(InstanceofMixin.call({
|
||||||
/**
|
/**
|
||||||
* Creates a `Base` instance
|
* Creates a `Base` instance
|
||||||
* @memberof Barricade.Base
|
* @memberof Barricade.Base
|
||||||
|
@ -592,7 +569,7 @@ var Barricade = (function () {
|
||||||
create: function (json, parameters) {
|
create: function (json, parameters) {
|
||||||
var self = this.extend({}),
|
var self = this.extend({}),
|
||||||
schema = self._schema,
|
schema = self._schema,
|
||||||
isUsed, id;
|
isUsed;
|
||||||
|
|
||||||
self._parameters = parameters = parameters || {};
|
self._parameters = parameters = parameters || {};
|
||||||
|
|
||||||
|
@ -608,16 +585,14 @@ var Barricade = (function () {
|
||||||
|
|
||||||
Observable.call(self);
|
Observable.call(self);
|
||||||
Omittable.call(self, isUsed);
|
Omittable.call(self, isUsed);
|
||||||
|
Deferrable.call(self, schema);
|
||||||
Validatable.call(self, schema);
|
Validatable.call(self, schema);
|
||||||
|
|
||||||
if (schema.hasOwnProperty('@enum')) {
|
if (schema.hasOwnProperty('@enum')) {
|
||||||
Enumerated.call(self, schema['@enum']);
|
Enumerated.call(self, schema['@enum']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( Object.hasOwnProperty.call(parameters, 'id') ) {
|
Identifiable.call(self, parameters.id);
|
||||||
id = parameters.id;
|
|
||||||
}
|
|
||||||
Identifiable.call(self, id);
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
},
|
},
|
||||||
|
@ -738,7 +713,7 @@ var Barricade = (function () {
|
||||||
? this._getPrettyJSON(options)
|
? this._getPrettyJSON(options)
|
||||||
: this._getJSON(options);
|
: this._getJSON(options);
|
||||||
}
|
}
|
||||||
})));
|
}));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class
|
* @class
|
||||||
|
@ -757,15 +732,9 @@ var Barricade = (function () {
|
||||||
var self = Base.create.call(this, json, parameters);
|
var self = Base.create.call(this, json, parameters);
|
||||||
|
|
||||||
return self.on('_addedElement', function (key) {
|
return self.on('_addedElement', function (key) {
|
||||||
// every time a new element is added we need to set the
|
|
||||||
// listeners for it and try to resolve any references,
|
|
||||||
// passing the resolution upward if needed
|
|
||||||
self._attachListeners(key);
|
self._attachListeners(key);
|
||||||
self._tryResolveOn(self.get(key));
|
self._tryResolveOn(self.get(key));
|
||||||
}).each(function (index, value) {
|
}).each(function (index, value) {
|
||||||
// also we bind the handlers and do reference resolution
|
|
||||||
// for all the children that are already here (no upward
|
|
||||||
// resolution here)
|
|
||||||
self._attachListeners(index);
|
self._attachListeners(index);
|
||||||
value.resolveWith(self);
|
value.resolveWith(self);
|
||||||
});
|
});
|
||||||
|
@ -825,8 +794,21 @@ var Barricade = (function () {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_isCorrectType: function (instance, class_) {
|
_isCorrectType: function (instance, class_) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
function isRefTo() {
|
||||||
|
if (typeof class_._schema['@ref'].to === 'function') {
|
||||||
|
return self._safeInstanceof(instance,
|
||||||
|
class_._schema['@ref'].to());
|
||||||
|
} else if (typeof class_._schema['@ref'].to === 'object') {
|
||||||
|
return self._safeInstanceof(instance,
|
||||||
|
class_._schema['@ref'].to);
|
||||||
|
}
|
||||||
|
throw new Error('Ref.to was ' + class_._schema['@ref'].to);
|
||||||
|
}
|
||||||
|
|
||||||
return this._safeInstanceof(instance, class_) ||
|
return this._safeInstanceof(instance, class_) ||
|
||||||
class_.isValidRef(instance);
|
(class_._schema.hasOwnProperty('@ref') && isRefTo());
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -911,10 +893,10 @@ var Barricade = (function () {
|
||||||
* @memberof Barricade.Arraylike
|
* @memberof Barricade.Arraylike
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_sift: function (json, parameters) {
|
_sift: function (json) {
|
||||||
return json.map(function (el) {
|
return json.map(function (el) {
|
||||||
return this._keyClassCreate(
|
return this._keyClassCreate(
|
||||||
this._elSymbol, this._elementClass, el, parameters);
|
this._elSymbol, this._elementClass, el);
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1070,11 +1052,11 @@ var Barricade = (function () {
|
||||||
* @memberof Barricade.ImmutableObject
|
* @memberof Barricade.ImmutableObject
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_sift: function (json, parameters) {
|
_sift: function (json) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return this.getKeys().reduce(function (objOut, key) {
|
return this.getKeys().reduce(function (objOut, key) {
|
||||||
objOut[key] = self._keyClassCreate(
|
objOut[key] =
|
||||||
key, self._keyClasses[key], json[key], parameters);
|
self._keyClassCreate(key, self._keyClasses[key], json[key]);
|
||||||
return objOut;
|
return objOut;
|
||||||
}, {});
|
}, {});
|
||||||
},
|
},
|
||||||
|
@ -1211,12 +1193,10 @@ var Barricade = (function () {
|
||||||
* @memberof Barricade.MutableObject
|
* @memberof Barricade.MutableObject
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_sift: function (json, parameters) {
|
_sift: function (json) {
|
||||||
return Object.keys(json).map(function (key) {
|
return Object.keys(json).map(function (key) {
|
||||||
var params = Object.create(parameters);
|
return this._keyClassCreate(this._elSymbol, this._elementClass,
|
||||||
params.id = key;
|
json[key], {id: key});
|
||||||
return this._keyClassCreate(
|
|
||||||
this._elSymbol, this._elementClass, json[key], params);
|
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -131,11 +131,12 @@ describe('merlin models:', function() {
|
||||||
},
|
},
|
||||||
'linkedField': {
|
'linkedField': {
|
||||||
'@class': fields.linkedcollection.extend({
|
'@class': fields.linkedcollection.extend({
|
||||||
create: function(json, parameters) {
|
create: function(json) {
|
||||||
parameters = Object.create(parameters);
|
var parameters = {
|
||||||
parameters.toCls = collectionCls;
|
toCls: collectionCls,
|
||||||
parameters.neededCls = linkedObjCls;
|
neededCls: linkedObjCls,
|
||||||
parameters.substitutedEntryID = 'realCollection';
|
substitutedEntryID: 'realCollection'
|
||||||
|
};
|
||||||
return fields.linkedcollection.create.call(this, json, parameters);
|
return fields.linkedcollection.create.call(this, json, parameters);
|
||||||
},
|
},
|
||||||
_dropDownLimit: 4
|
_dropDownLimit: 4
|
||||||
|
|
Loading…
Reference in New Issue