ractive-ractive
Ractive adaptor for Ractive objects
Last updated 5 years ago by rstacruz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ractive-ractive 
SYNC missed versions from official npm registry.

ractive-ractive

Experimental ractive adaptor for ractive objects. This makes it possible to use template-less Ractive objects as models.

Find more Ractive.js plugins at docs.ractivejs.org/latest/plugins

Status

Note for v0.x users:

v1.0.0 changes the behavior of doing require('ractive-ractive') (eg, in Browserify). See the changelog for upgrade instructions.


Example

Ractive.defaults.adapt.push('Ractive');

parent = new Ractive();
user   = new Ractive();

parent.set('user', user);

Changes in children are propagated to the parent:

user.set('name', 'Jake');
parent.get('user.name')   //=> "Jake"

Changes in the parent are propagated to the children:

parent.set('user.name', 'Matt');
user.get('name')   //=> "Matt"

Features

Everything you'd expect to work will work.

  • bi-directional propagation
  • observers
  • templates
  • computed properties

However, these things are not supported, but may be in the future:

  • circular dependencies (an error will be thrown)
  • events (see ractive#1249)

Wrap events

It will trigger a few events:

  • wrap - called when the instance is set as an attribute of another instance
  • unwrap - called when the instance has been unset from its parent
  • wrapchild - called when the instance gets an Ractive attribute set
  • unwrapchild - called when the instance gets an Ractive attribute unset

To illustrate:

parent = new Ractive();
child  = new Ractive();

parent.set('x', child);
// triggers `wrap(parent, 'x')` on child
// triggers `wrapchild(child, 'x')` on parent

parent.set('x', undefined);
// triggers `unwrap(parent, 'x')` on child
// triggers `unwrapchild(child, 'x')` on parent

Usage

ractive-ractive is available via npm.

$ npm install --save ractive-ractive

npm version

In CommonJS:

Ractive.adaptors.Ractive = require('ractive-ractive');
Ractive.defaults.adapt = ['Ractive'];

Without module loaders, the adaptor is available as "Ractive" under Ractive.adaptors.Ractive.


Credits

Hat tip to the original Ractive adaptor from @Rich-Harris. (src)


Thanks

ractive-ractive © 2014+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz

Current Tags

  • 1.1.1                                ...           latest (5 years ago)

14 Versions

  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 0.4.5                                ...           6 years ago
  • 0.4.4                                ...           6 years ago
  • 0.4.3                                ...           6 years ago
  • 0.4.2                                ...           6 years ago
  • 0.4.1                                ...           6 years ago
  • 0.4.0                                ...           6 years ago
  • 0.3.2                                ...           6 years ago
  • 0.3.1                                ...           6 years ago
  • 0.3.0                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (7)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |