donaldaverill / meteor-package-actions

Actions for Meteor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Actions for Meteor Build Status

An umbrella package for Reflux with a new namespace.

Install

meteor add fourquet:actions

Works well with Stores, Routes, and Logs (coming soon).

Reflux needs to be included in the app with a package such as fourquet:reflux-core, fourquet:reflux or from NPM.

Example:

// example.js

if (Meteor.isClient) {
  Session.setDefault('counter', 0);
  Actions.Client = Actions.createActions([
    'counterAction',
    'consoleAction'
  ]);
  Actions.Client.counterAction.listen((count = 0) =>  {
    Session.set('counter', count);
  });
  Actions.Client.consoleAction.listen((count = 0) =>  {
    console.log('consoleAction fired with value : ', count);
  });
  Template.hello.helpers({
    counter() {
      return Session.get('counter');
    }
  });
  Template.hello.events({
    'click button'() {
      Actions.Client.counterAction(Session.get('counter') + 1);
      Actions.Client.consoleAction(Session.get('counter') + 1);
    }
  });
}

if (Meteor.isServer) {
  Actions.Server = Actions.createActions([
    'timerAction'
  ]);
  Actions.Server.timerAction.listen((count = 0) => {
    console.log('timeAction fired at:', count);
  });
  let timer = 0;
  const timerSpeed = 2000;
  Meteor.setInterval(() => {
    Actions.Server.timerAction(timer);
    timer += timerSpeed;
  }, timerSpeed);
}

See the example app for more.

Version

0.0.1

License

MIT

About

Actions for Meteor

License:MIT License


Languages

Language:JavaScript 90.9%Language:HTML 8.0%Language:CSS 1.1%