Giter VIP home page Giter VIP logo

Comments (4)

rpominov avatar rpominov commented on August 19, 2024

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.

RGBboy avatar RGBboy commented on August 19, 2024

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.

rpominov avatar rpominov commented on August 19, 2024

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.

rpominov avatar rpominov commented on August 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.