spyne
Version:
Reactive Real-DOM Framework for Advanced Javascript applications
58 lines (50 loc) • 1.48 kB
JavaScript
import { Channel } from './channel.js'
import { SpyneAppProperties } from '../utils/spyne-app-properties.js'
import { Subject, ReplaySubject, merge } from 'rxjs'
import { includes } from 'ramda'
import { delayCall } from '../utils/frp-tools.js'
export class ChannelProxy extends Channel {
/**
* @module ChannelProxy
* @type internal
*
* @constructor
* @param {String} name
* @param {Object} props
*
* @desc
* A proxy channel is created when a channel is subscribed to before it is registered.
*
*/
constructor(name, props = {}) {
props.isProxy = true
super(name, props)
this.props = props
this.subject$ = new Subject()
this.replaySub$ = new ReplaySubject(1)
this.observer$ = merge(this.subject$, this.replaySub$)
const isDevMode = SpyneAppProperties.debug
if (isDevMode === true) {
this.checkIfChannelIsStillProxy(name)
}
}
getMergedSubject(peristData = false) {
return peristData === true ? this.replaySub$ : this.subject$
}
checkIfChannelIsStillProxy(channelName) {
const name = channelName
const checkIfProxy = () => {
const bool = includes(name, SpyneAppProperties.listRegisteredChannels())
if (bool !== true) {
console.warn(`Spyne Warning: The channel, ${name} does not appear to be registered!`)
}
}
delayCall(checkIfProxy, 1000)
}
get replaySubject() {
return this.replaySub$
}
get subject() {
return this.subject$
}
}