• Stars
    star
    150
  • Rank 242,312 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Conductor.js

Build Status

Conductor.js is a library for creating sandboxed, re-usable apps that can be embedded inside a host application.

The advantage of using Conductor.js over a standard <iframe> is that it uses a well-defined set of events that allow the app and its host environment to communicate. Because of this, apps from different vendors can be embedded securely, yet still interact in meaningful ways.

Understanding Conductor.js

To understand the benefit of architecting your application using Conductor, let's look at an example use case.

Imagine that you are authoring a next-generation banking web application. When your customers visit their account online, you would like to present them with a list of their most recent transactions:

Wireframe of a hypothetical banking application where transactions are presented as a simple list, showing transaction date, merchant name and transaction value

This is fine, but is the same as every other bank. You, being a next-generation, technology-driven bank, want to make this data more meaningful to your customers. Most transactions have some metadata associated with them. What if you could allow merchants to customize how their transactions appeared?

Wireframe of a hypothetical banking application where transactions are presented in a rich way, including a logo of the merchant, and additional metadata. The first transaction is from a fast food restaurant and includes the patron's order in the transaction display. The second transaction is from an airline and shows the flight origin and destination, as well as the customer's frequent flyer member number and point balance. The last transaction is from a hotel chain that shows the check-in and check-out date as well as the customer's reward points balance.

Obviously, you could write custom code for each merchant that might have a transaction go through your bank. But there are many merchants in the world, and you would most likely only have the resources to customize the most popular.

The better option is to have each merchant write and maintain their own transaction card. But how do you run that code in a way that doesn't make your customers' private financial data vulnerable to attack?

Running the code directly is out of the question. Normally, you might just create an <iframe> for each item in the transaction. That's fine, but how do provide information about the transaction to each transaction card? And what if you want to get information out of the card?

For example, imagine we wanted to group transactions by type. Instead of guessing, we could ask each transaction what category it belongs to, then show the user only travel-related transactions, for example.

Conductor.js allows you to define interfaces between a host environment and the cards that run inside of it, without having to write messy and brittle transports over postMessage.

Cards are also designed to be run on the server, so they can be indexed and otherwise manipulated without having to create a memory- and CPU-intensive virtual browser.

And, because cards are run inside either iframes or Web Workers, they cannot get access to any data that is not explicitly provided.

The above example is just one use for Conductor.js. There are many different scenarios where being able to embed secure, third-party code can allow you to build a platform of re-usable components that can interact with their host environment.

Authoring Conductor.js Cards

A card is an application that can be embedded in a parent environment using Conductor.js. The entry point to a card is an HTML page that loads Conductor.js.

At its most basic, your card should call the Conductor.card method. The object passed to Conductor.card defines the behavior of the card, and contains callbacks and other hooks that will be invoked in response to requests from the containing environment.

For example, the activate hook is invoked automatically once all dependencies have finished loading, and communication with the parent environment has been set up:

Conductor.card({
  activate: function() {
    this.alert("Hello!")
  }
});

Loading Dependencies

A card can load additional javascript dependencies by using the Conductor.require method:

Conductor.require('alert.js');

Note that files loaded via Conductor.require are loaded asynchronously. That means that, assuming the Model class was defined in models.js, this would not work:

Conductor.require('models.js');
var person = new Model();

Make sure you only access dependencies once the card's activate method has been called:

Conductor.require('alert.js');

function createModel() {
  var person = new Model();
}

Conductor.card({
  activate: function() {
    createModel();
  }
});

You can include CSS files in your card using the Conductor.requireCSS method:

Conductor.requireCSS('card.css');

The path is relative to the card.

Tutorial

Learn more about authoring cards in the tutorial.

Build Tools

Conductor.js uses Grunt to automate building and testing.

Setup

Before you use any of the commands below, make sure you have installed node.js, which includes npm, the node package manager.

If you haven't before, install the grunt CLI tool:

$ npm install -g grunt-cli

This will put the grunt command in your system path, allowing it to be run from any directory.

Next, install Conductor's dependencies:

$ npm install

This will install all of the packages that Conductor's Gruntfile relies on into the local node_modules directory.

Building

Conductor is available as either as an AMD module, or as a more traditional distribution that exports the global variable Conductor. To build both versions, run:

grunt build

You can find the built versions of the library in the dist directory.

Tests

Run the Conductor tests by starting a test server:

grunt server

Once the server is running, visit http://localhost:8000 in your browser. Conductor will automatically be rebuilt if you make any changes to its constituent files while the server is running.

More Repositories

1

rsvp.js

A lightweight library that provides tools for organizing asynchronous code
JavaScript
3,619
star
2

helix

Native Ruby extensions without fear
Rust
1,980
star
3

htmlbars

A variant of Handlebars that emits DOM and allows you to write helpers that manipulate live DOM nodes
JavaScript
1,607
star
4

router.js

TypeScript
1,348
star
5

route-recognizer

A lightweight JavaScript library that matches paths against registered routes. It includes support for dynamic and star segments and nested handlers.
TypeScript
461
star
6

bloggr-client

The Source for the Ember Get Excited Video
JavaScript
310
star
7

oasis.js

A lightweight library for embedding untrusted content and exposing capabilities. I guess it does two things? But it does them well.
JavaScript
281
star
8

simple-html-tokenizer

A lightweight JavaScript library for tokenizing non-`<script>` HTML expected to be found in the `<body>` of a document
TypeScript
85
star
9

learning-rust

Rust
67
star
10

kamino.js

Kamino.js is a library for passing data structures between sandboxed environments in the browser via `postMessage`.
JavaScript
48
star
11

ember-element-helper

Dynamic element helper for Glimmer templates.
JavaScript
42
star
12

ember-async-await-helper

Awaits a promise, then yields its result to a block. 👌
JavaScript
40
star
13

slackathon

A simple way to build slack interations inside a Rails app.
Ruby
31
star
14

MessageChannel.js

JavaScript
27
star
15

bound-templates.js

Bound Templates provides an interface similar to Polymer's MDV less invasively on more browsers (by using wrapper objects and an HTML parser written in JavaScript)
JavaScript
25
star
16

broccoli-typescript-compiler

TypeScript
24
star
17

json-normalizer

A small, lightweight library for normalizing JSON properties and values.
JavaScript
24
star
18

helix-rails

Helix for Rails
Ruby
22
star
19

libkit

JavaScript
17
star
20

ts-std

A standard library for TypeScript, extracted from Glimmer and other Tilde projects
TypeScript
10
star
21

buffoon

A protobuf library for Rust
Rust
10
star
22

selector-generator

A lightweight JavaScript library that generates CSS selectors from DOM nodes.
JavaScript
10
star
23

canal.js

Canal.js is a lightweight JavaScript library for creating channels, which are objects that represent a stream of events.
JavaScript
10
star
24

ember-control-flow-component

The superclass for all your "control-flow" component needs
9
star
25

ember-women

The Ember Women Helping Women Program
CSS
8
star
26

libcruby-sys

Rust
8
star
27

helix-website

Website for the Helix project
Ruby
8
star
28

kafka-librato-reporter

Report Kafka metrics to Librato
Java
8
star
29

sync.js

JavaScript
6
star
30

range-serializer

A lightweight JavaScript library that serializes/deserializes DOM range objects.
JavaScript
6
star
31

helix-flipper

A simple Rails app to get you started with Helix
Ruby
5
star
32

jsframe.js

Convert JavaScript to (near) JavaScript/HTML polyglot.
JavaScript
4
star
33

oasis-website

Oasis.js helps you structure communication between multiple untrusted sandboxes
CSS
3
star
34

ember-template-string-interpolation

JavaScript
3
star
35

rustconf

Annual Rust Conference
HTML
3
star
36

ember-training-june-day2

JavaScript
3
star
37

discourse-refcount-resource-spike

JavaScript
2
star
38

skiplist.js

JavaScript
2
star
39

ember-training-nyc-june

Material for the Tilde training course in NYC
JavaScript
2
star
40

emberconf-meetups

A list of unofficial EmberConf meetups
2
star
41

ember-swappable-service

JavaScript
2
star
42

ember-better-attributes

An Ember plugin that provides a better attribute syntax, building on simple-html-tokenizer. It is expected to be merged into Ember in the future.
JavaScript
2
star
43

fastboot-test

JavaScript
1
star
44

rails_todo_app

Ruby
1
star
45

ruby-rust-musl

Test of building musl Rust extensions for Ruby
Ruby
1
star