Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. // Keeping the call site simple for the sake of example
  2. const container = {
  3. controller : function(){
  4. this.tracks = new Tracks() // Or however you want to do it
  5. this.showPlayer = true
  6. },
  7.  
  8. view : state =>
  9. m( '.Container',
  10. m( '.Stuff' ),
  11.  
  12. // Sub-component display is a property of the container
  13. this.showPlayer
  14. && m( TunesPlayer, {
  15. // Limit component input to the things it cares about,
  16. // saves having to share the entire application model accross all components
  17. track : state.tracks.selectedTrack,
  18. // No need to pre-define and label all possible interactions, just pass anonymous fns about
  19. close : () =>
  20. state.showPlayer = false
  21. } ),
  22.  
  23. m( '.Stuff' )
  24. )
  25. }
  26.  
  27. // Assuming the following is the discrete tunes-player module
  28. const TunesPlayer = {
  29. // Can tell ahead of time from the signature:
  30. // This component has no local state, but expects input
  31. view : ( {}, input ) =>
  32. m('div', {
  33. // Style is not a stateful property per-instance,
  34. // it's just a persistent static reference
  35. style
  36. },
  37. m('div',
  38. m('button.pure-button[style="float:right"]', {
  39. onclick: () =>
  40. input.close()
  41. }, 'x'),
  42.  
  43. m('div',
  44. // Limited concerns makes it easier to develop when the application model is in flux,
  45. // also allows portability to other applications that don't share a model,
  46. // plus limits the possibility space of what any given component can do.
  47. input.track.trackName
  48. ),
  49.  
  50. m('small',
  51. m.trust('by '),
  52.  
  53. m('cite',
  54. input.track.artistName
  55. )
  56. )
  57. ),
  58.  
  59. m('video[controls][autoplay]', {
  60. src : input.track.previewUrl,
  61. style : 'width: 24rem; margin: 0.5rem'
  62. } )
  63. )
  64. }
  65.  
  66. const style = `
  67. z-index: 10;
  68. position: fixed;
  69. top: 50%;
  70. left: 50%;
  71. margin-left: -12em;
  72. margin-top: -12em;
  73. width: 25rem;
  74. border: solid 1px #bbb;
  75. padding: 1rem;
  76. background-color: white;
  77. `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement