Coder Social home page Coder Social logo

icalialabs / ember-post-robot Goto Github PK

View Code? Open in Web Editor NEW
0.0 6.0 0.0 904 KB

krakenjs/post-robot as an Ember Addon

License: MIT License

JavaScript 81.50% HTML 18.50%
ember ember-addon popup-messaging popup-windows popup post-messaging postmessaging promise

ember-post-robot's Introduction

ember-post-robot

Ember Observer Score npm version

This ember addon allows consumption of the post-robot library - A cross domain post-messaging on the client side using a simple listener/client pattern - in ember-cli apps.

Using ember-post-robot

Adding it to your app

You can install this addon to your ember > 2.3.0 app using EmberCLI:

ember install ember-post-robot

Importing post-robot

You can include post-robot into your controllers, routes, components or any class that requires it with an ES6 import:

import PostRobot from 'post-robot';

The PostRobot export contains all the methods of the krakenjs/post-robot library.

Sending Messages

In this example, we'll send a message to an iframe from a controller action:

import Ember from 'ember';
import PostRobot from 'post-robot';

export default Ember.Controller.extend({
  actions: {
    notifyIframe(iframeId) {
      let someIframe = window.document.getElementById(iframeId);
      if (isBlank(someIframe)) return;
      PostRobot.send(someIframe, 'org.example.message', { body: 'This is an example' });
              //  .then(notifySuccess)
              //  .catch(notifyFailure);
    },
  }
});

See more examples on the krakenjs/post-robot README.

Receiving Messages

In this example, we'll receive a message from another iframe in a route:

import Ember from 'ember';
import PostRobot from 'post-robot';

export default Ember.Route.extend({
  messageListener: null,

  activate() {
    // Return if the listener is already activated!
    if (Ember.isPresent(this.get('messageListener'))) return;

    this.set(
      'messageListener',
      PostRobot.on('org.example.messagee', (message) => { Ember.Logger.info(message.body); })
    );
  },

  deactivate() {
    // Let's make sure the listener will no longer be active:
    let listener = this.get('messageListener');
    if (Ember.isBlank(listener)) return;

    listener.cancel();
    this.set('messageListener', null);
  }
});

Testing

  • npm test (Runs ember try:each to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit https://ember-cli.com/.

Some useful links

ember-post-robot's People

Contributors

ember-tomster avatar vovimayhem avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.