ractive-state-router
A RactiveJS-based rendering layer for the abstract-state-router
Last updated 10 months ago by tehshrike .
WTFPL · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ractive-state-router 
SYNC missed versions from official npm registry.

Use Ractive with abstract-state-router!

Install

npm + your favorite CommonJS bundler is easiest.

npm install ractive-state-router

You can also download the stand-alone build from bundle.run. If you include it in a <script> tag, a ractiveStateRouter function will be available on the global scope.

Breaking changes

In version 7, the "active state" decorator changed from taking a string of state name/options to be parsed apart, to taking the state name, options object, and an optional class name.

Usage

var StateRouter = require('abstract-state-router')
var Ractive = require('ractive')
var makeRactiveStateRenderer = require('ractive-state-router')
var domready = require('domready')

var renderer = makeRactiveStateRenderer(Ractive)

var stateRouter = StateRouter(renderer, 'body')

// add whatever states to the state router

domready(function() {
	stateRouter.evaluateCurrentRoute('login')
})

makeRactiveStateRenderer(Ractive, [ractiveOptions, [options]])

ractiveOptions is an object that is passed into Ractive.extend and takes Ractive's options.

options is an object with one optional property: deepCopyDataOnSet (defaults to false). When true, the content from the resolve function will be deep copied before being set on the Ractive object, in order to try to maintain the immutability of whatever objects you pass in.

var StateRouter = require('abstract-state-router')
var Ractive = require('ractive')
var RactiveRenderer = require('ractive-state-router')

var renderer = RactiveRenderer(Ractive, {
	data: { hello: 'world' }
})
var stateRouter = StateRouter(renderer, 'body')

In templates

The active decorator adds the active class to an element if the given state is currently active. It takes three arguments: a state name (string), an optional parameters object, and a class name to be applied to the element if the state is active (defaults to 'active').

The makePath function from the abstract-state-router is also exposed.

<li as-active="'app.some-state', { parameter: 'somevalue' }, 'totally-active'">
	<a href="{{ makePath('app.some-state') }}">Some state</a>
</li>

Passing templates to addState

When calling the abstract-state-router's addState function, you may provide any of these values as the template:

  • a Ractive template string
  • a parsed Ractive template object
  • an object of Ractive initialization options to instantiate the Ractive object with. Should contain a template property.

Current Tags

  • 8.1.0                                ...           latest (10 months ago)

19 Versions

  • 8.1.0                                ...           10 months ago
  • 8.0.0                                ...           2 years ago
  • 7.1.0                                ...           4 years ago
  • 7.0.0                                ...           4 years ago
  • 6.1.3                                ...           4 years ago
  • 6.1.2                                ...           4 years ago
  • 6.1.1                                ...           4 years ago
  • 6.1.0                                ...           4 years ago
  • 6.0.0                                ...           5 years ago
  • 5.2.0                                ...           5 years ago
  • 5.1.0                                ...           5 years ago
  • 5.0.0                                ...           6 years ago
  • 4.0.0                                ...           6 years ago
  • 3.2.1                                ...           6 years ago
  • 3.2.0                                ...           6 years ago
  • 3.1.0                                ...           6 years ago
  • 3.0.0                                ...           6 years ago
  • 2.1.0                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 1
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2016 © taobao.org |