Last active
August 29, 2015 14:13
-
-
Save DavidSouther/4f77cdfb34cae8293fa3 to your computer and use it in GitHub Desktop.
Song Flux Demo Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('trkstr.player.actions', [ | |
'songFlux' | |
]).factory('PlayerActions', function(songFactory){ | |
function Action(){ | |
this.module = this.module || 'trkstr'; | |
this.dispatcher = songFactory.getDispatcher(this.module); | |
} | |
Action.prototype.dispatch = function(){ | |
this.dispatcher.dispatch(this); | |
}; | |
function LoadAction(){ | |
this.purpose = 'Request dispatched stores refresh their in-memory data.'; | |
Action.call(this); | |
} | |
LoadAction.prototype = Object.create(Action.prototype); | |
function PlayAction(track){ | |
this.track = track; | |
this.purpose = 'Request a track be played.'; | |
Action.call(this); | |
} | |
PlayAction.prototype = Object.create(Action.prototype); | |
return { | |
Load: LoadAction, | |
Play: PlayAction | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function LibraryController(Library, Actions) { | |
this.Library = Library; | |
this.Actions = Actions; | |
} | |
LibraryController.prototype.play = function(track) { | |
return this.Actions.PlayAction(track).dispatch(); | |
}; | |
LibraryController.$inject = ['TrkstrLibrary', 'TrkstrActions']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function PlayerController(store) { | |
this.store = store; | |
this.store.on(this.store.Events.TrackChanged, this.play.bind(this)); | |
this.play(); | |
} | |
PlayerController.prototype.play = function() { | |
return this.track = this.store.currentTrack; | |
}; | |
PlayerController.$inject = ['PlayerStore']; | |
function PlayerDirective() { | |
this.controller = PlayerController; | |
this.templateUrl = 'player'; | |
this.replace = false; | |
this.restrict = 'E'; | |
this.controllerAs = 'state'; | |
this.bindToController = true; | |
this.scope = {}; | |
} | |
PlayerDirective.factory = function() { | |
return new PlayerDirective(); | |
}; | |
PlayerDirective.factory.$inject = []; | |
angular.module('trkstr.player.component', [ | |
'trkstr.stores.player', 'player.template' | |
]).directive('player', PlayerDirective); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PlayerFactory = function(Actions, song) { | |
function PlayerStore() { | |
global.EventEmitter.call(this); | |
this.module = 'trkstr'; | |
this.dispatcher = song.getDispatcher(this.module); | |
this.Events = PlayerStore.Events; | |
this.currentTrack = { | |
title: "Nothing Playing..." | |
}; | |
this.doPlay = this.dispatcher.register(Actions.PlayAction, this.play.bind(this)); | |
} | |
PlayerStore.prototype = Object.create(EventEmitter.prototype); | |
PlayerStore.prototype.play = function(playAction) { | |
this.currentTrack = playAction.track; | |
return this.emit(PlayerStore.Events.TrackChanged); | |
}; | |
PlayerStore.Events = { | |
TrackChanged: 'TrackChanged' | |
}; | |
return new PlayerStore(); | |
}; | |
PlayerFactory.$inject = [ 'TrkstrActions', 'songFlux' ]; | |
angular.module('trkstr.stores.player', [ | |
'trkstr.actions', 'songFlux' | |
]).factory('PlayerStore', PlayerFactory); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment