-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage with EventEmitter: pass all arguments to the Stream #60
Comments
I don't know how we'd do it. Would the arguments be passed as an Array? |
i don't know either, yet. what i did in my attempt was to establish a convention or better a contract, that everything wat is put to a chain of transforms will be profvided to user code in the same way as consumed. But, nody is more strikt a has a slightly different goal. i currently experimenting, if i can use highland in the same way as i thought about nody. i have three options in mind, to replace nody with highland, to combine them, or to rewrite nody with highland under the hood. i'm testing the first one currenly. so back to the issue. the problem is that streams are generically working with one value at a time, eventemmiters are not restricted to that. so the ony solution i see is to wrap the values into a container, either an array or object or just pass the arguments object of the event handler. that would work, in fact this is what i do currently in my experiment. it's simple, but i don't like it very much, because the knowledge about the structure of the data is lost then, also you have to deal with that the whole chain. but this might be a minor, since we often deal with that in js. and we always could add a map stream to the chain to rebuild the object. so something like that might be viable: _('request', httpServer /*optional param, may be for this case only: */, remapFunction)
// and in the constructor the event emitter branch:
if (typeof xs === 'string') {
ee.on(xs, function () {
var x = typeof mapperFunction === 'function' ?
mapperFunction.apply( null, slice.call(arguments) ) : arguments[0];
self.write(x);
});
} of course, as mentioned before, one could add own map stream, so we don't need this remap function here, but the event stream must provide all params to consumers in the first place. with the remaping the highland user can impose it own desired structure on the provided data. this is simple enough i think. i tried with nody to get to the point, where the user of the lib shouldn't care about wrapping and unwrapping, so she/he just provide functions and can asume all params be fine ordered as expected. this, because nody is meant to be a architecture design tool, specific to provide a generic interface and interaction of modules. i don't think it makes sence for highland to do so, it's purpose seems more generic to me. so the wrapping thinkg would satisfy me for now :) |
perhaps you could specify the arguments you'd like to consume as an _(ee, 'request', ['req', 'res']).map(function (x) {
// x.req and x.res now exist
}) On 4 April 2014 11:37, Gregor Elke notifications@github.com wrote:
|
so the highland event handler would do the mapping like function(){
var ctx = {}
names.forEach(function(name, idx){
ctx[name] = arguments[idx]
})
stream.write(ctx)
} this would be great, yes |
and if you wanted them as an array perhaps you could just pass a number as _(ee, 'request', 2).map(function (xs) {
// xs[0] is req, xs[1] is res
}) On 4 April 2014 14:52, Gregor Elke notifications@github.com wrote:
|
yeah. i'd be happy to contribute that btw. |
Excellent, I await your pull request :) Also, note that I messed up the argument order a bit there ... it should be On 4 April 2014 14:59, Gregor Elke notifications@github.com wrote:
|
i wondered a bit :) |
* optional wrapping for arguments an event emitter may pass to the event handler
Fixed by #63 |
Hey, Highland looks nice, i'm trying it out currently. What bothers me now is the fact that a stream, that wraps an EventEmitter instance, passes only the first argument with it. It prevents me from doing stuf like
is it posible to wrap the params in some way and pass them along?
The text was updated successfully, but these errors were encountered: