shrub/pkg/interface/src/views/apps/term/api.tsx

48 lines
923 B
TypeScript
Raw Normal View History

2020-05-01 05:54:12 +03:00
import _ from 'lodash';
export default class Api {
constructor(ship, channel) {
this.ship = ship;
2020-05-01 05:54:12 +03:00
this.channel = channel;
this.bindPaths = [];
}
bind(path, method, ship = this.ship, appl = 'herm', success, fail) {
2020-05-01 05:54:12 +03:00
this.bindPaths = _.uniq([...this.bindPaths, path]);
window.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);
2020-05-01 05:54:12 +03:00
}
action(appl, mark, data) {
return new Promise((resolve, reject) => {
this.channel.poke(window.ship, appl, mark, data,
(json) => {
resolve(json);
},
(err) => {
reject(err);
});
});
}
}