currere

v0.2.1
iFrame api helper.

Currere

An easy way to publish an api to communicate with iFrames.

Example

parent

const api = {
  foo: function (message) {
    console.log("foo called with: ", message);
  },
  version: '0.0.1',
};

currere(api).then((api) => {
  api.bar('nachos').then((val) => { console.log('and returned: ', val); });
});

iFrame

const api = {
  bar: function (message) {
    console.log("bar called with: ", message);
    return 46;
  }
};

currere(api).then((api) => {
  api.foo('cheese').then((val) => { console.log('and returned: ', val); });
  console.log('version', api.version)
});

this would produce the following in your console

version 0.0.1                   
bar called with:  nachos
foo called with:  cheese
and returned:  46
and returned:  undefined

Caveats

All api methods must return a "JSON serializable" value. (i.e. no functions)

Why "Currere"?

"Currere" is a latin word meaning "to run". It is also the word that "courier" (meaning messenger) is derived from. Both "run" (as in run a function) and "messenger" (as in postMessage api) seemed relevant to this project.

npm i currere

Metadata

  • MIT
  • Whatever
  • Unknown
  • released 2/23/2017

Downloads

Maintainers