Last active
July 1, 2016 17:01
-
-
Save dabit3/1baf41346e96db1bfd91e763ab4eedc7 to your computer and use it in GitHub Desktop.
React Native + MobX listStore.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {observable} from 'mobx' | |
let index = 0 | |
class ObservableListStore { | |
@observable list = [] | |
addListItem (item) { | |
this.list.push({ | |
name: item, | |
items: [], | |
index | |
}) | |
index++ | |
} | |
removeListItem (item) { | |
this.list = this.list.filter((l) => { | |
return l.index !== item.index | |
}) | |
} | |
addItem(item, name) { | |
this.list.forEach((l) => { | |
if (l.index === item.index) { | |
l.items.push(name) | |
} | |
}) | |
} | |
} | |
const observableListStore = new ObservableListStore() | |
export default observableListStore | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment