Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RawDataWorker #1975

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions data/service/data-service-reference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
var Montage = require("core/core").Montage,
ModuleReference = require("core/module-reference").ModuleReference;

/**
* @class DataServiceReference
* @extends external:Montage
*/
exports.DataServiceReference = Montage.specialize(/** @lends DataServiceReference.prototype */ {



initWithIdTypesAndRequire: {
value: function (id, types, require) {
if (!id || !require) {
throw new Error("Module ID and require required");
}
this.module = new ModuleReference().initWithIdAndRequire(id, require);
this.types = types;

return this;
}
},

/**
* The identifier is the name of the service and is used to make the
* serialization of models more readable.
* @type {string}
* @default this.name
*/
identifier: {
get: function () {
return [
"dataService",
(this.serviceName || this.prototypeName || "unnamed").toLowerCase(),
"reference"
].join("_");
}
},

initWithModuleAndTypes: {
value: function (serviceModule, types) {
if (!serviceModule) {
throw new Error("Module is required");
}
this.module = serviceModule;
this.types = types;

return this;
}
},


deserializeSelf: {
value: function (deserializer) {
this.super(deserializer);
var value;

value = deserializer.getProperty("module");
this.module = value;

value = deserializer.getProperty("serviceName");
this.serviceName = value;

value = deserializer.getProperty("prototypeName");
this.prototypeName = value;

value = deserializer.getProperty("types") || [];
this.types = value;
}
},

serializeSelf: {
value: function (serializer) {
this.super(serializer);
}
},

promise: {
get: function () {
var prototypeName;
if (!this._promise) {
prototypeName = this.prototypeName;
this._promise = this.module ? this.module.exports.then(function (exports) {
var service = exports.montageObject;
if (!service && prototypeName) {
service = new exports[prototypeName];
//TODO Add Types To Service
}
return service;
}) : Promise.resolve(null);
}
return this._promise;
}
},

module: {
value: undefined
},

moduleId: {
get: function () {
return this.module && this.module.id || undefined;
}
},

prototypeName: {
value: undefined
},

serviceName: {
value: undefined
},

types: {
value: undefined
}

});
67 changes: 64 additions & 3 deletions data/service/data-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,20 @@ exports.DataService = Montage.specialize(/** @lends DataService.prototype */ {
Array.prototype.push.apply(this._childServiceMappings, value);
}

this.registerSelf();

value = deserializer.getProperty("delegate");
if (value) {
this.delegate = value;
}

if (this._childServiceRegistrationPromise) {
this._childServiceRegistrationPromise = this._childServiceRegistrationPromise.then(function () {
return self.registerSelf();
});
} else {
this._childServiceRegistrationPromise = this.registerSelf();
}

return result;
}
Expand Down Expand Up @@ -281,6 +291,15 @@ exports.DataService = Montage.specialize(/** @lends DataService.prototype */ {
// types or to the "all types" service array identified by the
// `null` type, and add each of the new child's types to the array
// of child types if they're not already there.
this._cacheServiceWithTypes(child, types);
// Set the new child service's parent.
child._parentService = this;
}
},

_cacheServiceWithTypes: {
value: function (child, types) {
var children, type, i, n, nIfEmpty = 1;

for (i = 0, n = types && types.length || nIfEmpty; i < n; i += 1) {
type = types && types.length && types[i] || null;
Expand All @@ -293,8 +312,6 @@ exports.DataService = Montage.specialize(/** @lends DataService.prototype */ {
}
}
}
// Set the new child service's parent.
child._parentService = this;
}
},

Expand Down Expand Up @@ -397,6 +414,48 @@ exports.DataService = Montage.specialize(/** @lends DataService.prototype */ {
}
},

registerSelf: {
value: function () {
var self = this,
mappings = this.mappings || [],
types;

// possible types
// -- types is passed in as an array or a single type.
// -- a model is set on the child.
// -- types is set on the child.
// any type can be asychronous or synchronous.
types = types && Array.isArray(types) && types ||
types && [types] ||
this.model && this.model.objectDescriptors ||
this.types && Array.isArray(this.types) && this.types ||
this.types && [this.types] ||
[];

return this._registerOwnTypesAndMappings(types, mappings).then(function () {
self._cacheServiceWithTypes(self, types);
return self;
});
}
},

_registerOwnTypesAndMappings: {
value: function (types, mappings) {
var self = this,
objectDescriptors;
return this._resolveAsynchronousTypes(types).then(function (descriptors) {
objectDescriptors = descriptors;
self._registerTypesByModuleId(objectDescriptors);
return self._registerChildServiceMappings(self, mappings);
}).then(function () {
return self._makePrototypesForTypes(self, objectDescriptors);
}).then(function () {
// self.addChildService(child, types);
return null;
});
}
},

_resolveAsynchronousTypes: {
value: function (types) {
var self = this;
Expand Down Expand Up @@ -1747,7 +1806,8 @@ exports.DataService = Montage.specialize(/** @lends DataService.prototype */ {
//have to go up to answer that question. The difference between
//.TYPE and Objectdescriptor still creeps-in when it comes to
//the service to answer that to itself
if (self.parentService && self.parentService.childServiceForType(query.type) === self && typeof self.fetchRawData === "function") {
service = self.parentService ? self.parentService.childServiceForType(query.type) : self.childServiceForType(query.type);
if (service === self && typeof self.fetchRawData === "function") {
service = self;
service._fetchRawData(stream);
} else {
Expand All @@ -1760,6 +1820,7 @@ exports.DataService = Montage.specialize(/** @lends DataService.prototype */ {
stream = service.fetchData(query, stream) || stream;
self._dataServiceByDataStream.set(stream, service);
} else {
debugger;
throw new Error("Can't fetch data of unknown type - " + (query.type.typeName || query.type.name) + "/" + query.type.uuid);
}
} catch (e) {
Expand Down
45 changes: 45 additions & 0 deletions data/service/raw-data-operation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var Montage = require("core/core").Montage;

/**
* Represents
*
* @class
* @extends external:Montage
*/
exports.RawDataOperation = Montage.specialize(/** @lends DataOperation.prototype */ {

/***************************************************************************
* Constructor
*/

constructor: {
value: function RawDataOperation() {
this.time = Date.now();
this._index = exports.RawDataOperation.prototype._currentIndex + 1 || 0;
exports.RawDataOperation.prototype._currentIndex = this._index;
}
},

data: {
value: undefined,
serializable: "value"
},

objectDescriptorModule: {
value: undefined,
serializable: "value"
},

serviceModule: {
value: undefined,
serializable: "value"
},

type: {
value: undefined,
serializable: "value"
}


});

2 changes: 1 addition & 1 deletion data/service/raw-data-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ exports.RawDataService = DataService.specialize(/** @lends RawDataService.protot
// if (childService && childService.identifier.indexOf("offline-service") === -1) {
// childService._fetchRawData(stream);
// } else
if (childService) {
if (childService && childService !== this) {
childService._fetchRawData(stream);
} else if (query.authorization) {
stream.query = self.mapSelectorToRawDataQuery(query);
Expand Down
Loading