meteor-community-packages / meteor-eventemitter Goto Github PK
View Code? Open in Web Editor NEWClient and server event emitter
License: MIT License
Client and server event emitter
License: MIT License
Hi,
Does it supports emitting an event from server to client and from client to server?
We lack an emitter to simulate a state
an example could be the cordova ready event where we want to be notified when a state changes, if a state is already set we will run the listener at registration.
Another use case is for the raix:push
package where a push message can be set before Meteor is even ready/after ready etc. So the message can be interpreted as a state, eg. we want to get the state and updates.
cc: @arunoda (If you have input or opinion about this)
Is ist possible to emit an event from the server and process it on the client? I am trying below. I have a setInterval running on my server to emit the number data to the client but doesn't seem to work. If I move my server code to the client it works perfectly. Not sure if this is possible or out of the scope of this package.
server.js
Meteor.startup(function(){ Event = new EventEmitter(); Meteor.setInterval(function(){ console.log("Emitting") Event.emit('game-spin', { number: 6 }) },2000); })
client.js
var listener; Meteor.startup(function(){ Event = new EventEmitter(); }) Template.gamePartial.onCreated(function() { listener = function(data) { console.log('Listening custom event', data); }; Event.on('game-spin', listener); }) Template.gamePartial.onDestroyed(function() { Event.removeListener('game-spin', listener); })
It seems to me like wrapping a reactive variable in a Tracker.autorun accomplishes the exact same thing as an event emitter but with more declarative syntax as opposed to imperative syntax... Just curious when you'd want to use an event emitter as opposed to a reactive variable?
It would be awesome if this would work seamlessly with Template events. That way they can automatically unsubscribe and it gives a very unified feel to the Template code...
as meteor starts to remove underscore everywhere, we should also remove it here.
this package is used by the widely used collection2 package
Both return "self" which is undefined in those functions.
Would be nice to get some more docs and examples or guides.
As node.js documentation says: "Inside a listener function, this refers to the EventEmitter that the listener was attached to".
can a server event quickly show on the client ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.