UNPKG

@awcrotwell/motion

Version:

Motion allows you to build reactive, real-time frontend UI components in your Amber application using pure Crystal that are reusable, testable & encapsulated. For brevity, we will call them MotionComponents.

35 lines (34 loc) 941 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const extend = function (object, properties) { if (properties != null) { for (const key in properties) { const value = properties[key]; object[key] = value; } } return object; }; class Subscription { constructor(consumer, params = {}, mixin) { this.consumer = consumer; this.channel = params.channel; this.identifier = params; extend(this, mixin); } // Perform a channel action with the optional data passed as an attribute perform(data) { return this.send(data); } send(data) { return this.consumer.send({ command: 'process_motion', identifier: this.identifier, data, }); } unsubscribe() { return this.consumer.subscriptions.remove(this); } } exports.default = Subscription;