(->Emberpusher = (channel, store, model) ->@channel = channel@store = store@model = model@channel.bind"created",(pushed_model)=>console?.log('created'+JSON.stringify(pushed_model))foo = @store.find(@model,pushed_model.id)iffoo.stateManager?.currentState?.name=='inFlight'# do nothing, same process created itelseiffoo.get('id')foo.setProperties(pushed_model)foo.stateManager.goToState('loaded')else@store.load(@model,pushed_model)@channel.bind"updated",(pushed_model)=>console?.log('updated'+JSON.stringify(pushed_model))foo = @store.find(@model,pushed_model.id)iffoo.get('id')andfoo.stateManager?.currentState?.name!='inFlight'foo.setProperties(pushed_model)foo.stateManager.goToState('loaded')else@store.load(@model,pushed_model)@channel.bind"destroyed",(pushed_model)=>console?.log('destroyed'+JSON.stringify(pushed_model))foo = @store.find(@model,pushed_model.id)iffoo.stateManager?.currentState?.name=='inFlight'# nothingelseiffoo.get('id')foo.deleteRecord()@Emberpusher = Emberpusher).callthis
As you can see, I’m wrestling with the state machine implementation and I’m not winning. All I wanted to do was say, here’s a new authoritative state for this model, but sometimes it gets into a ‘loading’ or ‘loaded’ state which must be a race condition. Clearly, I shouldn’t be messing with the state machine, or, I could spend more time reading the tests to get all the states and then correct the above but I can’t justify more time spent.
Hopefully this helps someone else carry it across the line.