You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
936 B
JavaScript
36 lines
936 B
JavaScript
'use strict';
|
|
|
|
const createEventEmitter = require("create-event-emitter");
|
|
|
|
module.exports = function createSynchronizableAsset(initialUrl, initialVersion, initialPriority, initialMetadata) {
|
|
let asset = createEventEmitter({
|
|
sources: [],
|
|
primarySource: initialSource,
|
|
getUrl: function () {
|
|
return this.primarySource.url;
|
|
},
|
|
getPrimarySource: function () {
|
|
return this.primarySource;
|
|
},
|
|
addSource: function addSource(url, version, priority, metadata) {
|
|
let newSource = {
|
|
url: url,
|
|
version: version,
|
|
priority: priority,
|
|
metadata: metadata
|
|
};
|
|
|
|
this.sources.push(newSource);
|
|
|
|
if (this.primarySource == null || (version >= this.primarySource.version && priority > this.primarySource.priority)) {
|
|
this.primarySource = newSource;
|
|
this.emit("newPrimarySource", newSource);
|
|
}
|
|
}
|
|
});
|
|
|
|
asset.addSource(initialUrl, initialVersion, initialPriority, initialMetadata);
|
|
|
|
return asset;
|
|
};
|