You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.
For now Connection API is a ES6 class with a lot of methods, used inconsistently along the codebase. I have experimented for some time with a different ways how to change the design, and would like to share my findings.
Treat connections as a generic objects without defining a class.
From the typescript point of view these objects should provide Duplex Stream interface and Peer Info interface (have properties peerInfo and a method getObservedAddrs).
Creating new connection objects using factories and transformation functions.
Why this approach is interesting? Well, see:
Factory
functionattachPeerInfo(stream: Duplex,peerInfo: PeerInfo): Connection{stream.peerInfo=peerInfoif(stream.observer)stream.observer(stream,peerInfo,'new','peerInfo')returnstream// Actually a connection}
Attaching the observer to the connection, so that observer function is called for each message:
import{tap}from'pull-tap'exportfunctionobserveDuplexStream(stream,observer){stream.observer=observer// This will allow to easely get stream.peerInfolet_out=tap(msg=>stream.observer(stream,stream.peerInfo,'out',msg))let_in=tap(msg=>stream.observer(stream,stream.peerInfo,'in',msg))// Monkey-patching the underlying streamsstream.source=pull(stream.source,_out)stream.sink=pull(_in,stream.sink)returnstream}
That's all. There is no need to define a complex interaction on the data. Observer will see the peerInfo on the stream when it appears.
3) The proxy stream with an observer and a different peerInfo attached:
const{ duplex }=require('pull-defer')functioncreateProxyConnection(swarm): Connection{letproxy=duplex()// Basically a mixins that define the connection behaviourobserveDuplexStream(proxy,swarm.observer)attachPeerInfo(proxy,swarm.peerInfo)// it's created! returnproxy}
What do you think?
Also this would allow to add any number of annotations. ES6 Symbols can be used to get rid of name collision problems.
The text was updated successfully, but these errors were encountered:
For now Connection API is a ES6 class with a lot of methods, used inconsistently along the codebase. I have experimented for some time with a different ways how to change the design, and would like to share my findings.
Why this approach is interesting? Well, see:
That's all. There is no need to define a complex interaction on the data. Observer will see the peerInfo on the stream when it appears.
3) The proxy stream with an observer and a different peerInfo attached:
What do you think?
Also this would allow to add any number of annotations. ES6 Symbols can be used to get rid of name collision problems.
The text was updated successfully, but these errors were encountered: