Skip to content
This repository has been archived by the owner on Jul 25, 2020. It is now read-only.
/ ractive-model Public archive

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

License

Notifications You must be signed in to change notification settings

ElliotChong/ractive-model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ractive-model

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

Ractive-Model is forked from [@rstacruz]'s ractive-ractive module and takes a wrapper-based approach to nesting Ractive models rather than applying the child data properties directly on the parent.

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


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-model is available via npm.

$ npm install --save ractive-model

npm version

Require the module to use. No need to consume the return value.

require('ractive-model')

Credits

Hat tip to the original Ractive adaptor from @Rich-Harris. (src) Kudos for the original ractive-ractive from [@rstacruz]. (src)


Thanks

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

GitHub @ElliotChong  ·  Twitter @ElliotChong

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published