donaldaverill / meteor-package-routes

An extension of kadira:flow-router to work with fourquet:actions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Routes for Meteor Build Status

An extension of kadira:flow-router to work with fourquet:actions

Install

meteor add fourquet:routes

Routes extends kadira:flow-router and compliments fourquet:actions(Actions). In order to use Routes, Reflux needs to be included in the app with a package such as fourquet:reflux-core, fourquet:reflux or from NPM.

Documentation

Routes can listen to action and perform actions. First, define actions:

Actions.SomeActions = Actions.create([
  'anAction',
  'anotherAction'
]);

Then listen:

Routes.listenTo(Actions.SomeActions.anAction, () => {
  // do something, such as render a page
});

When an action is called, Routes will call its function.

Actions.SomeActions.anAction();

Example

See the repository for full working example.

<template name="layout">
  <h1>Welcome to the Routes Example!</h1>
  <div><a href="/">Home</a></div>
  <div><a href="/anotherPage">Another Page</a></div>
  {{> Template.dynamic template=main}}
</template>

<template name="home">
  This is home!
</template>

<template name="anotherPage">
  This is anotherPage!
</template>
Actions.Main = Actions.createActions([
  'goToHome',
  'goToAnotherPage',
]);

Routes.route('/', {
  name: 'home',
  action() {
    Actions.Main.goToHome();
  },
});
Routes.route('/anotherPage', {
  name: 'anotherPage',
  action() {
    Actions.Main.goToAnotherPage();
  },
});

if (Meteor.isClient) {
  Routes.listenTo(Actions.Main.goToHome, () => {
    BlazeLayout.render('layout', {
      main: 'home'
    });
  });

  Routes.listenTo(Actions.Main.goToAnotherPage, () => {
    BlazeLayout.render('layout', {
      main: 'anotherPage'
    });
  });
}

Todo

More tests

Version

0.0.2

License

MIT

About

An extension of kadira:flow-router to work with fourquet:actions

License:MIT License


Languages

Language:JavaScript 83.6%Language:HTML 16.4%