Skip to content

Commit

Permalink
Store as data
Browse files Browse the repository at this point in the history
close #1
  • Loading branch information
yang-wei committed Jul 12, 2015
1 parent fe4f7ce commit 56e0ee0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
25 changes: 16 additions & 9 deletions src/store/ItemStore.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
import MicroEvents from 'microevent-github'
import AppDispatcher from '../AppDispatcher'

const _items = [{title: 'Item #1'}, {title: 'Item #2'}, {title: 'Item #3'}]
const _items = [{title: 'Item #1'}, {title: 'Item #2'}, {title: 'Item #3'}]

class itemStore {
constructor(items = []) {
this.items = items
this.newItem = { title: ''}
}

const ItemStore = {
addItem(item) {
_items.push( item )
},
this.items.push( item )
}

removeItem(item) {
let index = _items.indexOf(item);
_items.splice(index, 1);
},
const index = this.items.indexOf(item);
this.items.splice(index, 1);
}

resetItem() {
return { title: ''}
},
}

getAll() {
return _items
return this.items
}
}

const ItemStore = new itemStore(_items)

MicroEvents.mixin(ItemStore)

AppDispatcher.register( payload => {
Expand Down
5 changes: 1 addition & 4 deletions src/view/items-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ const itemView = {
</div>
`,
data() {
return {
items: [],
newItem: ''
}
return ItemStore
},
compiled() {
this.update()
Expand Down

0 comments on commit 56e0ee0

Please sign in to comment.