Comments (4)
In Bacon.js there is Bus which is like Kefir's emitter, but you also can .plug
streams to it. In Kefir I decided to split Bus functionality to two objects — emitter and pool. There is no docs for pool yet, but it basically .plug
part of Bacon's Bus, except the method called .add
.
var p = Kefir.pool();
var e = Kefir.emitter();
p.add(e);
p.log();
e.emit(1);
> [pool] <value> 1
But now, when you asking, I am not still sure it was a good idea to split Bus functionality. Maybe we should add .plug
method to emitter, what do you think?
from kefir.
I think a .plug
method on emitter would be nice.
Here is an example of what I would like to be able to do:
var Kefir = require('kefir'),
service = require('service')(), // a kefir emitter for data from a given service
processInput,
processOutput,
output;
processInput = Kefir.emitter();
processOutput = processInput.map(
function (x) {
// do some transformation
return x + 1;
});
output = Kefir.emitter
.log('output');
// take output of service send it to the inputProcess
// then take the outputProcess
// and send it to an output
service.plug(processInput)
processOutput.plug(output);
It would also be nice to be able to describe a process in a contained way. Something similar to nodes duplex stream. For example:
var process = Duplex(processInput, processOutput);
process.log();
process.emit(1); // 2
process.emit(3); // 4
process.emit(5); // 6
That way plugging the top example could be simplified to:
service.plug(process).plug(ouput);
from kefir.
Looking at your example, it seems like you misunderstand of how .plug
works (in Bacon's Bus). When you call A.plug(B)
you force A
to listen to B
and repeat events from it, not other way round.
Also it seems like you expose some output from service (i.e. you send data from service to it's user), in this case I would expose not emitter, but just some stream (which may be an emitter or not) or a property. Then I would transform that stream without using any emitters, like that:
output = service.map(
function (x) {
// do some transformation
return x + 1;
});
output.log('output');
But, I think, emitter with .plug
method (i.e. Bacon's bus) is the best choice to expose as an API from a service when you want to give to users an opportunity to send some data to your service.
Maybe I'll just add Bus to Kefir, leaving emitter as it is. I will think about it.
from kefir.
As for version 0.2.8 Kefir now has .bus()
. I am closing this issue for now, please feel free to reopen it if you have further questions.
from kefir.
Related Issues (20)
- KefirJS and WebSockets HOT 4
- Only `sampledBy` is past tense
- Current state policies HOT 2
- Idea: Usable as AsycInterator
- Proposal to add `fromProperty` static function HOT 15
- Static Land interop `Observable` definition is wrong HOT 5
- Shouldn't a property only emit on "new values"? Proposing `onChange()` HOT 1
- Missing type for `unplug`
- Maintain TypeScript types? HOT 4
- Stop bundling `symbol-observable`
- TypeError: this._emitValue is not a function HOT 1
- Make subscription available inside callback HOT 8
- A big "Thank You" to Kefir developers HOT 1
- How to import Kefir within Rollup library HOT 3
- groupBy function HOT 8
- flatMapConcat should work when a spawned observable ends synchronously on activation
- Add documentation to "Kefir.pool" as "Rx.Subject equivalent" HOT 2
- Synchronous emit in flush method of debounce produces incorrect result HOT 8
- Is it possible to not activate a staled observable when reactivating flatMapLatest? HOT 8
- Russian docs translate
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kefir.