Sha256: 884d44d26b7cf37dd301b03ac322d4ae1367701b1b126b7cf1e50dcdd94b1002

Contents?: true

Size: 993 Bytes

Versions: 1

Compression:

Stored size: 993 Bytes

Contents

import { omit } from 'lodash';

import { logger } from '../../lib/util';
import { BaseModel } from '../base';

const CHANNEL_SPLITTER = new RegExp('^(.*):(.*)/([^/]+)$');

export default class PubSubCableChannel {
    constructor(pub_sub) {
        this.channel = pub_sub.cable.subscriptions.create(
            'pubsub', this,
        );
        this.pub_sub = pub_sub;
    }

    subscribe(channel) {
        logger.info(`[pubsub] subscribe to: ${channel}`);
        this.channel.perform('on', { channel });
    }

    unsubscribe(channel) {
        logger.info(`[pubsub] unsubscribe from: ${channel}`);
        this.channel.perform('off', { channel });
    }

    received(data) {
        const [channel, _, modelId, id] = Array.from(
            data.channel.match(CHANNEL_SPLITTER),
        );
        logger.info(`[pubsub] change recvd for: ${channel}`);
        const model = BaseModel.findDerived(modelId);
        this.pub_sub.onModelChange(model, id, omit(data, 'channel'));
    }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hippo-fw-0.9.5 client/hippo/models/pub_sub/channel.js