0.0.2 • Published 8 years ago

ember-miao v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
8 years ago

Ember-Miao

Ember integration for AltSchool MIAO (Multiple Independent Asynchronous Objects), a backend library for real-time events (current implemented using websockets).

See also Vishnu Backend API.

Installation

ember install git+ssh://git@github.com:AltSchool/ember-query-expressions.git

Then add options to config/environment.js:

  ENV = {
    emberMiao: {
      loggingEnabled: false,
      apiUrl: <your-miao-service-url>
    },

    APP: {}  
  };

Usage

To subscribe and unsubscribe to a MIAO channel from a route:

import Ember from 'ember';

import MiaoRouteMixin from 'ember-miao/mixins/routes/miao';

export default Ember.Route.extend(MiaoRouteMixin, {
  subscribeAloCompetency: Ember.on('activate', function() {
    const student = this.modelFor('student');
    const miaoChannelName = `miao://progression/students/${student.get('id')}/`;

    this.subscribeMiaoChannel(miaoChannelName);
  }),

  unsubscribeAloCompetency: Ember.on('deactivate', function() {
    const student = this.modelFor('student');
    const miaoChannelName = `miao://progression/students/${student.get('id')}/`;

    this.unsubscribeMiaoChannel(miaoChannelName);
  })
});

MiaoRouteMixin

Provides subscribeMiaoChannel(channelName), unsubscribeMiaoChannel(channelName) API. When a subscribed channel recieves an event, the corresponding action on the route will trigger (route actions are overridable, though the mixin provides sane defaults):

  • miaoCreate(modelName, modelIds)
  • miaoUpdate(modelName, modelIds)
  • miaoDelete(modelName, modelIds)
  • miaoRefresh(modelName, modelIds)
  • miaoSyncError(reason)
  • miaoSubscribeError(reason)
  • miaoCustomEvent(message)