[data] updated 0.0.1 -> 0.0.2

This commit is contained in:
tmshv committed 2017-01-03 06:30:03 +03:00
1 parent e9cb52d20b
commit e9ac51d675
7 files changed
+152 -81

No files matched your search

+38 -15
View File
@@ -1,21 +1,44 @@
import {EventEmitter} from 'events';
import {EventEmitter} from 'events'
export default class Data extends EventEmitter {
constructor(store) {
super();
this.save = true;
this.store = store;
}
constructor(store) {
super()
this.save = true
this.store = store
}
update(document) {
this.emit('update', document);
}
broadcast(data) {
this.emit('update', data)
}
disableSaving() {
this.save = false;
}
disableSaving() {
this.save = false
}
enableSaving() {
this.save = true;
}
enableSaving() {
this.save = true
}
async create(data) {
const id = data.id
if (!id) throw new Error('Field `id` not found in Data object')
const query = {id: id}
await this.store.update(query, data, {upsert: true})
const result = await this.store.findOne(query)
this.emit('update', result)
return result
}
async read(id) {
return this.store.findOne({id: id})
}
async find(query, skip = 0, limit = 0) {
const cursor = this.store
.find(query)
.skip(skip)
if (limit) cursor.limit(limit)
return await cursor.toArray()
}
}
+8 -6
View File
@@ -1,9 +1,11 @@
import Timeline from './Timeline';
import Schedule from './Schedule';
import Timeline from './Timeline'
import Schedule from './Schedule'
import Document from './Document'
export default class DataManager {
constructor(stores) {
this.timeline = new Timeline(stores.timeline);
this.schedule = new Schedule(stores.schedules);
}
constructor(stores) {
this.timeline = new Timeline(stores.timeline)
this.schedule = new Schedule(stores.schedules)
this.document = new Document(stores.documents)
}
}
+5
View File
@@ -0,0 +1,5 @@
import Data from './Data'
export default class Document extends Data {
}
+29 -33
View File
@@ -2,47 +2,43 @@ import Data from './Data';
export default class Schedule extends Data {
create(){
create() {
}
}
read(){
read() {
}
}
update(){
delete() {
}
}
delete(){
find(query) {
}
}
find(query){
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];
};
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);
}
let add = async(post) => {
let document = post;
if (this.save) {
document = await savePost(post);
}
this.broadcast(document);
return document;
};
return add(post);
}
}
+48 -24
View File
@@ -1,27 +1,51 @@
import Data from './Data';
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);
}
async create(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.broadcast(document)
return document
}
return add(post)
}
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.broadcast(document)
return document
}
return add(post)
}
}