mirror of
https://github.com/urbit/shrub.git
synced 2024-12-20 17:32:11 +03:00
208d8cebf9
Splits herm and the webterm interface out into their own directories for separate distribution. Webterm glob pending.
51 lines
981 B
TypeScript
51 lines
981 B
TypeScript
import _ from 'lodash';
|
|
|
|
export default class Api {
|
|
ship: any;
|
|
channel: any;
|
|
bindPaths: any[];
|
|
constructor(ship, channel) {
|
|
this.ship = ship;
|
|
this.channel = channel;
|
|
this.bindPaths = [];
|
|
}
|
|
|
|
bind(path, method, ship = this.ship, appl = 'herm', success, fail) {
|
|
this.bindPaths = _.uniq([...this.bindPaths, path]);
|
|
|
|
(window as any).subscriptionId = this.channel.subscribe(ship, appl, path,
|
|
(err) => {
|
|
fail(err);
|
|
},
|
|
(event) => {
|
|
success({
|
|
data: event,
|
|
from: {
|
|
ship,
|
|
path
|
|
}
|
|
});
|
|
},
|
|
(err) => {
|
|
fail(err);
|
|
});
|
|
}
|
|
|
|
belt(belt) {
|
|
return this.action('herm', 'belt', belt);
|
|
}
|
|
|
|
action(appl, mark, data) {
|
|
return new Promise((resolve, reject) => {
|
|
this.channel.poke(window.ship, appl, mark, data,
|
|
(json) => {
|
|
resolve(json);
|
|
},
|
|
(err) => {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|