jam-cloud/web/app/assets/javascripts/react-components/stores/UserStore.js.coffee

33 lines
682 B
CoffeeScript

$ = jQuery
context = window
logger = context.JK.logger
@UserStore = Reflux.createStore(
{
user: null
listenables: @UserActions
init: ->
this.listenTo(context.AppStore, this.onAppInit)
onAppInit: (@app) ->
@loadAnonymousUser()
loadAnonymousUser: () ->
@user = {id: null, has_redeemable_jamtrack: context.JK.currentUserFreeJamTrack, purchased_jamtracks_count:0, show_free_jamtrack: context.JK.currentUserFreeJamTrack }
@changed()
onLoaded:(user) ->
@user = user
@changed()
onModify: (changes) ->
@user = $.extend({}, @user, changes)
@changed()
changed:() ->
@trigger({user: @user})
}
)