A mithril mixin mixer.
mimix( [ mixin1, mixin2, etc ] )
is like { ...mixin1, ...mixin2, ...etc }
, but geared towards the semantics of Mithril virtual DOM nodes (vnodes), DOM properties, and lifecycle methods. The goal is to enable a form of behaviour composition more subtle than components, by allowing mixins describing vnode behaviour to be composed into a singular node.
When multiple mixins share a key:
- Multiple functions are bound into one which executes all of these with the same input context & arguments:
- if all return
false
,false
is passed on (ideal foronbeforeupdate
) - if any return a
Promise
, then the consuming context receives aPromise.all
of all return values (ideal foronbeforeremove
) - otherwise the last such function's output is passed through
- Arrays are concatenated (ideal for
children
) - Non-null Objects are merged into a new object (ideal for
style
) class
/className
entries are space separated
In all other cases, it behaves like a traditional object merge would and subsequent values override the previous.