Compose disposals in controller
Closed this issue · 4 comments
Hi guys,
I have an issue - i can't get access to compositions in event listeners.
Example:
show: ->
@compose 'details', Details, {attrs}
list = @compose 'list', List, {attrs}
@listenTo list, 'details:show', @_doSomething
_doSomething: ->
# This fails because details composition is `stale=true`
el = @compose 'details'
el.showDetails()
Solution 1:
@details = @compose 'details', Details, {attrs}
...
Issue:
on controller dispose @details will be disposed even it is present in next composition. This is fail.
Solution 2:
scopeVar = null
class Screen extends Chaplin.Controller
show: ->
scopeVar = @compose 'details', Details, {attrs}
Issue:
it looks sucks.
I have 2 proposals:
-
Rework composition so it will not have stale state after method execution
-
Make some convention like
@__details = ...
if it starts with__
it will not be disposed as @ disposals.
What do you think?
Hey.
See the proposal for changing @compose
API to @share
, @reuse
and @retrieve
in gh-643 which effectively solves this issue.
We are looking forward to adding it.
Ok great, currently this adds to my big Chaplin app some mess
@paulmillr i see it's pretty old (~5 months ago) discussion. Maybe it make sense to crate draft and start working on it? i can help
Yes — would be great if you can help with this.
Feel free to ask me if you will have any questions on predicted problems.