ractive v0.9.6 Release Notes
-
2017-10-23
๐ฅ Breaking changes
- Experimental parser transforms have been removed and replaced with a runtime construct associated with partials (see below)
๐ Bug fixes
- HTML comments will now render (#3103)
- Re-linking a linked path to itself will now throw a proper error instead of overflowing the stack (#3107)
- Adapted values now reset and teardown correctly (#3100, #3112)
- The default data for a component constructor is a function that returns an empty object rather than an empty object so that the component will inherit default data by default.
sharedGet
andstyleGet
are now actually implemented on Ractive constructors as was erroneously indicated in the notes for 0.9.4
๐ New features (experimental)
- Async components: Components added to the component registry may be a promise or a function that returns a promise. While the promise is unresolved, the template will be left blank or display an options
async-loading
partial if supplied. When the promise resolves, the component will be rendered or supplied to an optionalasync-loaded
partial as{{>component}}
if theasync-loaded
partial is supplied. If the promise rejects, the template will be emptied or theasync-failed
partial will be rendered, if supplied. - The low-level construct that enables async components is the super or macro partial, which is also available for general use. A macro partial is one that provides a function that takes a context handle that can set the partial's template at any time.
- Macro partials can also have scoped
css
using the same mechanism as components. - They are created with
Ractive.macro( ( handle, args ) => { ... }, { options } )
and should be passed into a partials registry - They can be invoked using regular partial syntax or using element syntax as a lightweight component e.g.
<macro attr1="{{foo}}">content partial</macro>
- The handle passed to the macro function can be used to:
- Do anything a normal context object can e.g.
get
,set
,observe
,listen
, etc - Create aliases to
@local
data for the macro's template e.g.handle.aliasLocal( 'name' )
andhandle.aliasLocal( 'foo.bar', 'foobar' )
, which creates an aliasname
for@local
and an aliasfoobar
for@local.foo.bar
, respectively. - Change the template for macro at any point using
handle.setTemplate( newTemplate )
wherenewTemplate
can be a string or template script id if runtime parsing is available or a pre-parsed template. - The
template
property of the handle is a safe copy of the template AST containing the macro, and thepartials
property is a safe shared copy of the partials available to the macro.
- Do anything a normal context object can e.g.
- The options available for
Ractive.macro
are:attributes
- an array of attribute names to reserve for the macro. Any attributes not present in this array are collected and made available to the macro as the{{>extra-attributes}}
partial.css
- a string or function used for creating CSS for the macrocssId
- the id to use for CSS scopingnoCssTransform
- iftrue
, the CSS will not be scopedcssData
- the base dictionary for the macro's style data
- The return object from the macro function can include a number of callbacks:
update(attrs)
- called whenever any reserved attributes change. Ifhandle.setTemplate
is called from this callback, it will not trigger an additional turn of the runloop, so it's a relatively efficient operation.render()
- called when the template is renderedinvalidate()
- called when any downstream template updatesteardown()
- called when the macro is being removed from the template e.g. on unrender or if the dynamic name of the partial changes
- Async components: Components added to the component registry may be a promise or a function that returns a promise. While the promise is unresolved, the template will be left blank or display an options