在孩子:
var moveEvent = new CustomEvent('the-graph-group-move',{ detail: { nodes: this.props.nodes,x: deltaX,y: deltaY },bubbles: true }); this.getDOMNode().dispatchEvent(moveEvent);
在父代:
componentDidMount: function () { this.getDOMNode().addEventListener("the-graph-group-move",this.moveGroup); },
这工作,但有一个React特定的方式,会更好吗?
The React way would be to pass callbacks down to children explicitly via props — . There’s no support for custom events w/ bubbling in React.
反应式编程抽象是正交的:
Programming interactive systems by means of the observer pattern is hard and error-prone yet is still the implementation standard in many production environments. We present an approach to gradually deprecate observers in favor of reactive programming abstractions. Several library layers help programmers to smoothly migrate existing code from callbacks to a more declarative programming model.
React的理念是基于Command模式:
参考文献
> Deprecating the Observer Pattern
> Command Pattern: Command History
> Component Interop with React and Custom Elements
> Building Redux in TypeScript
> How is Mithril Different from Other Frameworks – Mithril
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。