mirror of
https://github.com/nasa/openmct.git
synced 2025-04-27 22:39:51 +00:00
[Example] Bring in example persistence
Bring in BrowserPersistenceService as an example, to use as a stub to develop and integrate commonUI bundles against. WTD-574.
This commit is contained in:
parent
1b0303e517
commit
8e50078823
18
example/persistence/bundle.json
Normal file
18
example/persistence/bundle.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"extensions": {
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"provides": "persistenceService",
|
||||||
|
"type": "provider",
|
||||||
|
"implementation": "BrowserPersistenceProvider.js",
|
||||||
|
"depends": [ "$q", "PERSISTENCE_SPACE" ]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"constants": [
|
||||||
|
{
|
||||||
|
"key": "PERSISTENCE_SPACE",
|
||||||
|
"value": "mct"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
82
example/persistence/src/BrowserPersistenceProvider.js
Normal file
82
example/persistence/src/BrowserPersistenceProvider.js
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*global define*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stubbed implementation of a persistence provider,
|
||||||
|
* to permit objects to be created, saved, etc.
|
||||||
|
*/
|
||||||
|
define(
|
||||||
|
[],
|
||||||
|
function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function BrowserPersistenceProvider($q, SPACE) {
|
||||||
|
var spaces = SPACE ? [SPACE] : [],
|
||||||
|
caches = {},
|
||||||
|
promises = {
|
||||||
|
as: function (value) {
|
||||||
|
return $q.when(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
spaces.forEach(function (space) {
|
||||||
|
caches[space] = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
listSpaces: function () {
|
||||||
|
return promises.as(spaces);
|
||||||
|
},
|
||||||
|
listObjects: function (space) {
|
||||||
|
var cache = caches[space];
|
||||||
|
return promises.as(
|
||||||
|
cache ? Object.keys(cache) : null
|
||||||
|
);
|
||||||
|
},
|
||||||
|
createObject: function (space, key, value) {
|
||||||
|
var cache = caches[space];
|
||||||
|
|
||||||
|
if (!cache || cache[key]) {
|
||||||
|
return promises.as(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
cache[key] = value;
|
||||||
|
|
||||||
|
return promises.as(true);
|
||||||
|
},
|
||||||
|
readObject: function (space, key) {
|
||||||
|
var cache = caches[space];
|
||||||
|
return promises.as(
|
||||||
|
cache ? cache[key] : null
|
||||||
|
);
|
||||||
|
},
|
||||||
|
updateObject: function (space, key, value) {
|
||||||
|
var cache = caches[space];
|
||||||
|
|
||||||
|
if (!cache || !cache[key]) {
|
||||||
|
return promises.as(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
cache[key] = value;
|
||||||
|
|
||||||
|
return promises.as(true);
|
||||||
|
},
|
||||||
|
deleteObject: function (space, key, value) {
|
||||||
|
var cache = caches[space];
|
||||||
|
|
||||||
|
if (!cache || !cache[key]) {
|
||||||
|
return promises.as(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete cache[key];
|
||||||
|
|
||||||
|
return promises.as(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return BrowserPersistenceProvider;
|
||||||
|
}
|
||||||
|
);
|
Loading…
x
Reference in New Issue
Block a user