aaronc / freactive

High-performance, pure Clojurescript, declarative DOM library
http://documentup.com/aaronc/freactive
Eclipse Public License 1.0
387 stars 27 forks source link

Clarify transitions API & lifecycle callbacks. #8

Open aaronc opened 9 years ago

martinklepsch commented 9 years ago

👍

aaronc commented 9 years ago

Currently I've added support for data-state based transitions. If data-state is bound to some atom, rx, etc., if its value changes to new-state for instance, and :on-new-state transition callback (currently passed as metadata to the "hiccup" vector) will be fired if present.

Comments on this as well as what lifecycle callbacks should/shouldn't be present welcome.

BorisKourt commented 9 years ago

Just saw this pop up in the CLJS group: https://github.com/pleasetrythisathome/bardo Here is the group post: https://groups.google.com/forum/#!topic/clojurescript/JROUw58NPX0 And here is a possibly relevant example with OM: https://github.com/pleasetrythisathome/bardo/blob/master/examples/om.cljs

Maybe some ideas align enough for this to be delegated to an external library? I know that doesn't feel like it melds with your design goals, but still just throwing this out there.

aaronc commented 9 years ago

Yeah, well actually I was hoping that the easing functions could be delegated to an external library. This looks pretty good. I may suggest people use it in the README - the idea with freactive animations is to let people use whatever easing functions they like and ideally I'd prefer not to maintain that library...

aaronc commented 9 years ago

See https://github.com/aaronc/freactive/issues/7

aaronc commented 9 years ago

FYI in 0.2.0-SNAPSHOT all node life-cycle callbacks have been moved to the attribute map itself (where other DOM attrs are stored). Currently supported life-cycle callbacks are :node/on-attached which takes a single arg for the node and is suitable for animation, :node/on-detaching which takes the DOM node and a callback which must be called after any animation is complete and only called at binding/removal sites, and :node/on-disposed which takes no args currently.

Also planned are :node/on-moving, :node/on-moved and possibly a :node/on-created. I may add a single parameter to :node/on-created and :node/on-detaching which is a unique ID for the node (the node itself isn't sufficient because they get reused) - this is in case anyone really needs to do some complex resource mangement coordinated with node creation/disposal.

data-state transitions are now supported via the attribute map as :state/on-new-state callbacks. Callbacks receive 3 args: the node, the old state and the new state.

Binding-level life-cycle callbacks are attached as metadata to ref types (i.e. rx, atom, cursor etc.) via alter-meta!. Currently supported are for node bindings only now are :binding-initialized and :binding-disposed which take no args as well as :binding-invalidated which takes the currently bound node and the ref as args. :binding-invalidated also allows a :cancel return argument to cancel the current re-render - maybe this binding and its behavior should be thought out more thoroughly. Any input? For attribute bindings only :binding-disposed is currently supported but I intend to implement at least :binding-initialized.

Any input is welcome.