Skip to content
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

Proper Lifecycles #37

Open
brianmhunt opened this issue Aug 29, 2017 · 2 comments
Open

Proper Lifecycles #37

brianmhunt opened this issue Aug 29, 2017 · 2 comments
Milestone

Comments

@brianmhunt
Copy link
Member

Noting @vvs comment:

While we are at it, maybe a proper lifecycle for the components should be defined, not only a single onReady/afterRender?

Take a look at Vue.js take on component's lifecycle:
https://vuejs.org/v2/guide/instance.html#Lifecycle-Diagram

There's also Oracle JET's ojModule take (search for "ViewModel's Lifecycle"):
https://docs.oracle.com/middleware/jet210/jet/reference-jet/ojModule.html

@brianmhunt brianmhunt changed the title Component lifecycle Proper Lifecycles Nov 10, 2017
@brianmhunt
Copy link
Member Author

So looking at the Vue.js lifecycle, I think I've gotten a decent idea of where Lifecycles could be applied in KO.

Overall, there's no over-arching / explicit lifecycle for applyBindings.

However, we can apply life cycles to binding handlers and components.

Here's a first crack at it.

Binding handlers hooks

  • BeforeCreate
  • Created
  • Bound
  • Update
  • Updated
  • Disposing
  • Disposed

Components

  • All the binding handler hooks
  • Loading Definition
  • Applying Definition
  • Definition Applied

@brianmhunt brianmhunt added this to the Beta-1 milestone Dec 21, 2017
@ryansolid
Copy link

ryansolid commented Mar 14, 2019

Or how about a Hooks API instead? Those seem all the rage these days. React now uses useState to track observable state, useEffect to track computed side effects, and useMemo to track pure computed values. It's so cool that they found away to use observable primitives to avoid needing those pesky lifecycle functions at all. I even checked out the prior art section of their Documentation and they most pulled this idea from previous work of React focused libraries like Recompose and observable streams like RxJS. It's a good thing since before React I probably would never pictured a world without lifecycle methods that could work off ideas as simple as useState, useEffect, and useMemo. More that you can make stateful components with just a simple function. Just a function. The future is here.

Maybe there is a way Knockout can enter modern 2019 JS dev too with ko.observable, ko.computed, and ko.pureComputed.


Sarcasm aside. Don't go too far down this rabbit hole. Patterns are like hats. They go in and out of fashion. Keep it true to the fundamentals. It was only a matter of time before React acknowledged Knockout had the right pattern all along. Just don't expect them to admit it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants