-
Notifications
You must be signed in to change notification settings - Fork 1
Description
After using tangle now in multiple VSCode projects I've run into several patterns where the current interface design fails. Therefor I would like to suggest some (breaking) changes to the package:
Usage of RxJS
RxJS has a steep learning curve and hard to get for people not familiar with it. I personally struggle fixing some of the reported issues and wouldn't wonder if others do so too. I am not sure if there is a clear need for RxJS for the tangle usecase, there are other ways to accomplish the same.
I'ld suggest to simplify the code base and remove RxJS as dependency and rewrite the functionality using bare JS primitives.
State Updates
Currently tangle's broadcast method requires the whole state to be submitted, it would be nice if updates can be made on single object properties. Maybe we can have a broadcast and broadcastAll?
That said, currently a state can be everything which turns out to be not useful in reality. It seems weird to juggle with multiple client instances because you have multiple states. It seems more straightforward to say a state must be a Map which can contain multiple state properties.
Every state listener is triggered whenever any state property changes. This comes from the fact mentioned above as the current implementation interprets a state as one object and can't determine if just parts of the state has changed.
With the suggestion above we should ensure that listening on a state property only triggers the listener when that particular state property has changed, e.g.:
const ch = new Channel('foobar', {
counter: 0,
anotherProperty: true
});
bus.listen('counter', (counter) => console.log(`Counter update: ${counter}`))
bus.broadcast({ anotherProperty: false }) // <--- does not trigger listener aboveThis causes a lot of re-renders in the Marquee extension.
Event vs. State
In the current implementation event and state is handled separately but not when it comes to types. For example:
interface StateType {
counter: number
}
const ch = new Channel<StateType>('foobar', {
counter: 0
});
bus.emit('foobar', 'barfoo') // type issue as `foobar` is not part of `StateType`I suggest to not expect any types for event methods except you pass in a type, e.g.:
interface Events {
foobar: string
}
bus.emit<Events>('foobar', 'barfoo')