Skip to content

Instantly share code, notes, and snippets.

@dabit3
Last active July 1, 2016 17:01
Show Gist options
  • Save dabit3/1baf41346e96db1bfd91e763ab4eedc7 to your computer and use it in GitHub Desktop.
Save dabit3/1baf41346e96db1bfd91e763ab4eedc7 to your computer and use it in GitHub Desktop.
React Native + MobX listStore.js
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