(via https://www.youtube.com/watch?v=QU3LYeaiHsw)
seen from Malaysia
seen from Greece

seen from Singapore
seen from United Kingdom

seen from United States

seen from United States
seen from United States

seen from Malaysia
seen from United States
seen from India

seen from Malaysia
seen from United States
seen from Australia
seen from United States

seen from United States

seen from United Kingdom
seen from Chile

seen from United Kingdom
seen from Finland
seen from United Kingdom
(via https://www.youtube.com/watch?v=QU3LYeaiHsw)
Use EventEmitter for calling child component event from parent in React
via http://stackoverflow.com/questions/31177366/react-native-call-function-of-child-from-navigatorios In parent component, writes
//in import package parts import EventEmitter from 'EventEmitter'; //in your Component class componentWillMount() = => { this.eventEmitter = new EventEmitter(); } handleAction() => { this.eventEmitter.emit('SomeEvent', { someArg: 'argValue' }); }
Then pass on this.eventEmitter as props to child component.
<ChildComponent event={this.eventEmitter} />
Finally add a listener for handling events in child component.
import Subscribable from 'Subscribable'; var ChildComponent = React.createClass({ mixins: [Subscribable.Mixin], componentDidMount() { this.addListenerOn(this.props.events, 'SomeEvent', this.myEventHandler); }, //other code goes here }
Note that ES6 style classes do not support mixins, so you must write your child component class in legacy "createClass" style.
Node自定义事件
其实就是继承events的EventEmitter就可以了,然后就可以通过on去注册事件;emit去触发事件,removeListener去移除事件,简单例子如下:
var util = require('util');
var Et = require('events').EventEmitter;
function Ticker() {
var self = this;
setInterval(function(){self.emit("tick")},1000);
}
util.inherits(Ticker,Et);
var ticker = new Ticker();
ticker.on("tick",function() {
console.log("ticker");
});
这样自定义的Ticker就具有自定义事件的能力了
NodeJS Events and EventEmitter
Node.js Events and EventEmitter - http://www.sitepoint.com/nodejs-events-and-eventemitter/
Emitting Custom Events in Node.js - http://venodesigns.net/2011/04/16/emitting-custom-events-in-node-js/
Taking Baby Steps with Node.js – Implementing Events - http://elegantcode.com/2011/02/21/taking-baby-steps-with-node-js-implementing-events/
Node.js EventEmitter Tutorial - http://www.hacksparrow.com/node-js-eventemitter-tutorial.html
NodeJS Custom EventEmitter Events
NodeJS relies heavily on event callbacks. It allows your server to "do other stuff" or throttle down when you're waiting "on things to happen" instead of blocking.
To build your own objects that leverage event callbacks, NodeJS provides the EventEmitter prototype. To use EventEmitter as the basis of your custom objects you can:
var util = require('util'); var events = require('events'); var CustomObject = function() { ... do something }; util.inherits(CustomObject, events.EventEmitter); CustomObject.prototype.emitExampleEvent = function() { this.emit('custom_event', 1, 2, 3); }
Now you can:
var customObjectInstance = new CustomObject(); customObjectInstance.on('custom_event', function(x, y, z) { .. do something });
You'll notice I didn't set our custom object's prototype property in any of the following ways and used util.inherits instead. That's the preferred way to set up inheritance for Node. These are the unpreferred ways (and why).
CustomObject.prototype = new events.EventEmitter(); // this instantiates an instance of EventEmitter.prototype but also initializes it by calling the EventEmitter constructor
CustomObject.prototype.__proto__ = events.EventEmitter.prototype; // relying on __proto__
CustomObject.prototype = Object.create(events.EventEmitter.prototype); // technically correct and how you would set up inheritance on your non-Node objects, but util.inherits is the prefered way
via @sugendran
nodeのEventEmitterの話。
あと、process.EventEmitterではなくevents.EventEmitterを使うべきらしい。MLで議論されていたとのこと。
via tristanls on @github