-
-
Notifications
You must be signed in to change notification settings - Fork 924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend (present, previous) signature to all component methods #2098
Comments
That's probably feasible. Regarding component methods signature, we may also revisit the possibility of optionally returning a Promise for suspending a given phase as you suggested previously. React will support throwing Promises to that end, I hope we can manage that situation with just returning values. Edit: removed off-topic idea. |
@pygy I'm glad you bring this up. I've been exploring various component extension patterns for a while and I believe the practical possibilities of asynchronous lifecycle methods can be better exposed without implementing that proposal. I'd like to submit this proposal as an alternative to that one, because, with hindsight, Optionally promise-returning lifecycle methods are badI started working on a proof of concept for 'temporal components' about 6 months ago, but I've found it difficult to develop & expound on the idea because despite the nominal intuitive convenience of returning a promise for a 'blocking' To wit:
Allowing lifecycle methods to be potentially asynchronous exponentially increases the complexity of Mithril code interoperability and raises all sorts of edge cases where previously predictable assumptions give rise to devilish ambiguity. I recant the suggestion and am happy to discuss my strong opposition to it in any given context. But, as I intimated earlier, all the functionality it exposes can be achieved with a little more elbow grease in safer ways if we simply explode & expose the state of salient Promises. By chaining off the relevant promises and binding Binary signature lifecycle methods enable safer & greater power in the same domainThe alluring convenience in allowing any given method to return a promise — over the pattern described above — is that we are able to avoid some the object-oriented drudgery of juggling state properties and call forwarding by grouping otherwise disparate execution contexts into an overarching scope. In this respect it's similar to function components. Crucially, this is where this proposal shines — and like View components, it's an area where Mithril v1's judicious early design decisions allows us to leapfrog the patterns React is just beginning to explore. The killer straw man is one in which thanks to this signature extension, we are able to subsume const AllInOne = {
view: (now, then) => {
if(!then || then.tag != now.tag){
// oninit:
now.state.x = y
requestAnimationFrame(() => {
// oncreate:
now.dom.animate(/**/)
})
}
else if(now.attrs.x === then.attrs.x)
// onbeforeupdate:
return then.instance
else
requestAnimationFrame(() => {
// onupdate:
now.dom.animate(/**/)
})
return /* view */
}
} By effectively turning the Nonetheless, I think this pattern lends itself especially well to the original POJO component convention, especially in combination with the View component pattern, inasmuch as discrete concerns can be abstracted via higher order View components*: By exposing the previous Asynchronous IoC in the virtual DOM treeThis doesn't address React's promise-rejection-within-a-component-as-current-draw-cancelling-&-deferral-mechanism specifically. What I want to impress with the above is that thanks to Mithril v1's ingenious vnode API, with lifecycle mechanisms written with the benefit of hindsight on Reacts, we have (with a relatively small tweak) the power to subsume the practical concerns of their mechanism in a holistically better way. I demonstrated in #1182 how View components enable us to explicitly specify async inversion of control concerns that enable lower order components to influence higher order virtual DOM tree concerns. Using a similar mechanism to the above, a New possibilitiesSo far I've covered how we can address relatively familiar issues, but providing an API that gives access to the previous vnode in place as early as the initial lifecycle offers fantastic opportunities for resolving IoC hell as regards transition between discrete components / elements. We can hereby infer that the new node is an essentially different entity to the previous one in place and determine any manner of complex transition logic there. This also solves one of the key problems in generalising route resolver logic that allows an incoming route to keep the stale view in place while waiting for new initialisation conditions to resolve. * The View component allows for declarative vdom expressions to instantiate, manipulate & query state between nested virtual DOM entities on an ad-hoc basis by enabling all lifecycle attributes - including const View = {
view(v){ return (
v.attrs.view
?
v.attrs.view.apply(
this,
arguments,
)
:
v.children
)}
} |
I wanted to bring this up for discussion while public vnode-exposing API changes were fresh in people's minds off the back of #1744.
The proposal is to have view and all other lifecycle methods match the
onbeforeremove
(OBR) signature.This would in theory allow some interesting opportunities:
I haven't looked into feasibility.
Any thoughts?
The text was updated successfully, but these errors were encountered: