Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. // require() some stuff from npm (like you were using browserify)
  2. // and then hit Run Code to run it on the right
  3. const State = require('ampersand-state')
  4. const View = require('ampersand-view')
  5. const app = require('ampersand-app')
  6.  
  7. const state = State.extend({
  8. session: {
  9. userName: 'string'
  10. }
  11. })
  12.  
  13. const view = View.extend({
  14. template: '<div>Welcome! <span data-hook="userName"></span></div>',
  15. autoRender: true,
  16.  
  17. bindings: {
  18. 'app.state.userName' : {
  19. hook: 'userName',
  20. type: 'text'
  21. }
  22. }
  23. })
  24.  
  25. app.extend({
  26. initialize: function() {
  27. const hook = document.querySelector('#body')
  28.  
  29. this.state = new state()
  30. this.view = new view({
  31. el: hook
  32. })
  33. }
  34. })
  35.  
  36. window.app = app // debug access
  37. app.initialize() // start app
  38.  
  39. // This should set the username, which should update the
  40. // binding on the view. However, it does not. The value
  41. // is updated, but the binding is not triggered.
  42. //
  43. setTimeout(function() {
  44. console.debug('Before:', app.state.userName)
  45. app.state.userName = 'Joe'
  46. console.debug('After:', app.state.userName)
  47. }, 300)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement