You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a feature request to reinstate an older functionality of possum: extending an instance's states via composition. Previously we could use some internals to reach into a possum's .router() and extendStates(). These concepts no longer apply, so I came up with a couple solutions...
This works sort-of well, due to the recursive merging of stampit.props()... however, it's a source for silent errors if an implementer wants to have their own extended state. Due to the invocation order of .init blocks, I can't protect the implementer via the following...
letextender=stampit().init(function(){// won't work due to the order of init blocksif(this.states.extended){console.warn('careful: "extended" is a built in state, pick another name.')}this.states.extended={extendedHandler: function(){}}})
This won't work because possum's init() blocks are triggered first - which is where states are set/sealed and closed to further extension. I can change the composition ordering, I suppose, like this:
letbase=extender.compose(possum)// extender's .init() is triggered before possums.init(), so there's time to // create and modify the this.states object...letit=base()
However, digging into the props() .states object just feels wrong. What are your thoughts on this?
The text was updated successfully, but these errors were encountered:
I intentionally pulled that out, considering it the burden of the caller to merge the states object before constructing their instance. Possum would get too involved in guessing what the user intends for things like duplicates and so on.
I'd suggest you simply have an explicit composition object that brings together your state handlers and then pass that into possum.states; eg
I have a feature request to reinstate an older functionality of
possum
: extending an instance's states via composition. Previously we could use some internals to reach into a possum's.router()
andextendStates()
. These concepts no longer apply, so I came up with a couple solutions...This works sort-of well, due to the recursive merging of
stampit.props()
... however, it's a source for silent errors if an implementer wants to have their ownextended
state. Due to the invocation order of.init
blocks, I can't protect the implementer via the following...This won't work because possum's
init()
blocks are triggered first - which is where states are set/sealed and closed to further extension. I can change the composition ordering, I suppose, like this:However, digging into the
props() .states
object just feels wrong. What are your thoughts on this?The text was updated successfully, but these errors were encountered: