Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Keeping the call site simple for the sake of example
- const container = {
- controller : function(){
- this.tracks = new Tracks() // Or however you want to do it
- this.showPlayer = true
- },
- view : state =>
- m( '.Container',
- m( '.Stuff' ),
- // Sub-component display is a property of the container
- this.showPlayer
- && m( TunesPlayer, {
- // Limit component input to the things it cares about,
- // saves having to share the entire application model accross all components
- track : state.tracks.selectedTrack,
- // No need to pre-define and label all possible interactions, just pass anonymous fns about
- close : () =>
- state.showPlayer = false
- } ),
- m( '.Stuff' )
- )
- }
- // Assuming the following is the discrete tunes-player module
- const TunesPlayer = {
- // Can tell ahead of time from the signature:
- // This component has no local state, but expects input
- view : ( {}, input ) =>
- m('div', {
- // Style is not a stateful property per-instance,
- // it's just a persistent static reference
- style
- },
- m('div',
- m('button.pure-button[style="float:right"]', {
- onclick: () =>
- input.close()
- }, 'x'),
- m('div',
- // Limited concerns makes it easier to develop when the application model is in flux,
- // also allows portability to other applications that don't share a model,
- // plus limits the possibility space of what any given component can do.
- input.track.trackName
- ),
- m('small',
- m.trust('by '),
- m('cite',
- input.track.artistName
- )
- )
- ),
- m('video[controls][autoplay]', {
- src : input.track.previewUrl,
- style : 'width: 24rem; margin: 0.5rem'
- } )
- )
- }
- const style = `
- z-index: 10;
- position: fixed;
- top: 50%;
- left: 50%;
- margin-left: -12em;
- margin-top: -12em;
- width: 25rem;
- border: solid 1px #bbb;
- padding: 1rem;
- background-color: white;
- `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement