Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import {observable, computed} from 'mobx'
  2.  
  3. // ignore the two lines below, they just creates unique IDs for the todo
  4. var _nextId = 0
  5. function nextId(){ _nextId++; return _nextId }
  6.  
  7. // this is our domain model class
  8. export class Todo{
  9. // the ID of the current Todo
  10. // a unique id is automatically assigned when the todo object is instanced.
  11. id = nextId()
  12. // the text of the todo; notice the "@observable" decorator.
  13. // The decorator, imported from mobx library in the first line,
  14. // will tell that this value is observable and computed values or observer
  15. // will be notified and updated when it changes.
  16. @observable text = ''
  17. // is the todo done?
  18. @observable done = false
  19.  
  20. // computed values are values derived and automatically updated when the observed
  21. // observable values changes. For example we use it to determine whenever the todo is valid
  22. @computed get isValid(){
  23. // a text is required
  24. return this.text !== ''
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement