+ hudozka-data package; /api/v1/feed -> /api/v1/timeline; other updates
This commit is contained in:
1 parent
d0878ec296
commit
b96d66591f
14 files changed
+84
-59
No files matched your search
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
lib/
|
||||
.idea/
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "hudozka-data",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"compile": "babel --presets es2015,stage-0 src/ -d lib/",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.6.5",
|
||||
"babel-preset-es2015": "^6.6.0",
|
||||
"babel-preset-stage-0": "^6.5.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import {EventEmitter} from 'events';
|
||||
|
||||
export default class Data extends EventEmitter {
|
||||
constructor(store) {
|
||||
super();
|
||||
this.save = true;
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
update(document) {
|
||||
this.emit('update', document);
|
||||
}
|
||||
|
||||
disableSaving() {
|
||||
this.save = false;
|
||||
}
|
||||
|
||||
enableSaving() {
|
||||
this.save = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import Timeline from './Timeline';
|
||||
|
||||
export default class DataManager {
|
||||
constructor(stores) {
|
||||
this.timeline = new Timeline(stores.timeline);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import Data from './Data';
|
||||
|
||||
export default class Timeline extends Data {
|
||||
add(post) {
|
||||
let savePost = async(post) => {
|
||||
const id = post.id;
|
||||
const type = post.type;
|
||||
const query = {id: id, type: type};
|
||||
|
||||
await this.store.update(query, post, {upsert: true});
|
||||
let document = await this.store.find(query).limit(1).toArray();
|
||||
return document[0];
|
||||
};
|
||||
|
||||
let add = async(post) => {
|
||||
let document = post;
|
||||
if(this.save){
|
||||
document = await savePost(post);
|
||||
}
|
||||
|
||||
this.update(document);
|
||||
return document;
|
||||
};
|
||||
|
||||
return add(post);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
import DataManager from './DataManager';
|
||||
export default DataManager;
|
||||
Reference in new issue
Block a user