Ractive.js decorator helper plugin.
Currently two helper methods:
create()
for simple decorators that need no teardown and use the same function for initial load and update.combine()
for combining decorators. Ractive currently only allows one dectorator per element. This function creates a decorator that allows the use of multiple decorators
The helper functions are exposed as Ractive.decorators.create
and Ractive.decorators.combine
. Please note that they are meant to be invoked to create a decorator, and thus will not work as decorators themeselves. Also note that Ractive.decorators.create
is not required in order to use Ractive.decorators.combine
, through the examples below make use of it.
.create( fn )
Wraps the supplied function as a decorator, called both at load and update. No-op teardown functionality.
this
in the function refers to the decorated node.
.combine( [ { n1: d1 }, { n2: d2 }, ... ])
Wraps the supplied name/decorator pairs as a single decorator. The supplied array order is preserved in load and update.
The decorator is used in the template as:
decorator="alias: { name1: [arg1, arg2, argn], name2: [arg1, arg2, argn]}"
For single argument decortors, the array is optional:
decorator="alias: { name1: arg1, name2: [arg1, arg2]}"
You do not need to include all combined decorators:
decorator="alias: { name1: arg1 }"