Add localforage, basic cache service
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
import Service from '@ember/service';
|
||||||
|
import * as localforage from 'localforage';
|
||||||
|
|
||||||
|
function createStore(name) {
|
||||||
|
return localforage.createInstance({ name: `kredits:${name}` });
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class BrowserCacheService extends Service {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super(...arguments);
|
||||||
|
this.stores = {
|
||||||
|
contributors: createStore('contributors'),
|
||||||
|
contributions: createStore('contributions')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get contributors() {
|
||||||
|
return this.stores.contributors;
|
||||||
|
}
|
||||||
|
|
||||||
|
get contributions() {
|
||||||
|
return this.stores.contributions;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -230,7 +230,7 @@ export default Service.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getContributions () {
|
getContributions () {
|
||||||
return this.kredits.Contribution.all({page: {size: 200}})
|
return this.kredits.Contribution.all({page: {size: 30}})
|
||||||
.then(contributions => {
|
.then(contributions => {
|
||||||
return contributions.map(contribution => {
|
return contributions.map(contribution => {
|
||||||
contribution.contributor = this.contributors.findBy('id', contribution.contributorId.toString());
|
contribution.contributor = this.contributors.findBy('id', contribution.contributorId.toString());
|
||||||
|
|||||||
Generated
+24
@@ -15545,6 +15545,12 @@
|
|||||||
"integrity": "sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A==",
|
"integrity": "sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"immediate": {
|
||||||
|
"version": "3.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
|
||||||
|
"integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"import-fresh": {
|
"import-fresh": {
|
||||||
"version": "3.2.1",
|
"version": "3.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.1.tgz",
|
||||||
@@ -16768,6 +16774,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"lie": {
|
||||||
|
"version": "3.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz",
|
||||||
|
"integrity": "sha1-mkNrLMd0bKWd56QfpGmz77dr2H4=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"immediate": "~3.0.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
"linkify-it": {
|
"linkify-it": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.2.0.tgz",
|
||||||
@@ -16849,6 +16864,15 @@
|
|||||||
"integrity": "sha512-9M2KvGT6duzGMgkOcTkWb+PR/Q2Oe54df/tLgHGVmFpAmtqJ553xJh6N63iFYI2yjo2PeJXbS5skHi/QpJq4vA==",
|
"integrity": "sha512-9M2KvGT6duzGMgkOcTkWb+PR/Q2Oe54df/tLgHGVmFpAmtqJ553xJh6N63iFYI2yjo2PeJXbS5skHi/QpJq4vA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"localforage": {
|
||||||
|
"version": "1.7.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/localforage/-/localforage-1.7.3.tgz",
|
||||||
|
"integrity": "sha512-1TulyYfc4udS7ECSBT2vwJksWbkwwTX8BzeUIiq8Y07Riy7bDAAnxDaPU/tWyOVmQAcWJIEIFP9lPfBGqVoPgQ==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"lie": "3.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"locate-character": {
|
"locate-character": {
|
||||||
"version": "2.0.5",
|
"version": "2.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/locate-character/-/locate-character-2.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/locate-character/-/locate-character-2.0.5.tgz",
|
||||||
|
|||||||
@@ -67,6 +67,7 @@
|
|||||||
"kosmos-schemas": "^2.1.0",
|
"kosmos-schemas": "^2.1.0",
|
||||||
"kredits-contracts": "^5.5.0",
|
"kredits-contracts": "^5.5.0",
|
||||||
"loader.js": "^4.7.0",
|
"loader.js": "^4.7.0",
|
||||||
|
"localforage": "^1.7.3",
|
||||||
"ndjson": "github:hugomrdias/ndjson#feat/readable-stream3",
|
"ndjson": "github:hugomrdias/ndjson#feat/readable-stream3",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"qunit-dom": "^1.2.0",
|
"qunit-dom": "^1.2.0",
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { module, test } from 'qunit';
|
||||||
|
import { setupTest } from 'ember-qunit';
|
||||||
|
|
||||||
|
module('Unit | Service | browser-cache', function(hooks) {
|
||||||
|
setupTest(hooks);
|
||||||
|
|
||||||
|
test('it exists', function(assert) {
|
||||||
|
let service = this.owner.lookup('service:browser-cache');
|
||||||
|
assert.ok(service);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('creates kredits data stores', function(assert) {
|
||||||
|
let cache = this.owner.lookup('service:browser-cache');
|
||||||
|
assert.equal(cache.contributors._config.name, "kredits:contributors");
|
||||||
|
assert.equal(cache.contributions._config.name, "kredits:contributions");
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user