I'm using the brunch-with-chaplinjs boilerplate with some additional libs (sinon, selenium, chai and mocha). Now i want to pass a model from a view, a collection-view to be exact, to another controller for editing.
I can do this like this:
Chaplin.utils.redirectTo 'editaddress', model:@model
But this makes my url messy:
localhost:8080/editaddress?model=%5Bobject%20Object%5D
I can not seem to find any acceptable way to keep the url clean and still pass the whole model to the other controller without refetching the model from the server.
Normally you would use chaplin's composer, but is only is for reusing views.
You can do this is still but with a stack.
Create a stack in application.coffee
there you can store items while you change controller.
# This is hidden from all other files so it is save, if you don't use any AMD,
# you should place this inside the application object.
stack = []
module.exports = class Application extends Chaplin.Application
### Your program here ###
start: ->
# Other code here
Mediator.setHandler 'push', @push
Mediator.setHandler 'pop', @pop
###
# Push to temporary storage stack.
###
push: (item)->
push item
###
# Pop form temporary storage stack.
###
pop: ->
return stack.pop()
Now you can push to your stack from anywhere in your code like this:
Mediator.execute 'push', @model
And to retrieve your can use:
Mediator.execute 'pop'