How to use Flux and event emitter with .net MVC?

梦想的初衷 提交于 2019-11-30 15:40:04

问题


I am trying to learn the Flux pattern.

I learned to use React with .net MVC and rendered it server side.

I would like to learn Flux but all tutorials use node js.

I don't use node.

I don't know how to implement the Event Emitter part because it uses a node function.

https://www.codementor.io/reactjs/tutorial/react-js-flux-architecture-tutorial

About a 1/3 of the way down:

"Event Emitter – The event emitter is responsible for notifying subscribers after a store has completed any data action. Conversely, it also needs to be able to register observers for specific events. We’re going to be using Node’s event emitter in the todo application."

Given that Flux is simply a pattern, is there something that I can use with .net MVC, in the absence of node, to handle the Event Emitter part?

Thoughts appreciated, thanks.


回答1:


You can use .NET Delegates, which is well documented here https://msdn.microsoft.com/en-us/library/edzehd2t%28v=vs.110%29.aspx

Delegates are multicast, which means that they can hold references to more than one event-handling method.

This will of course be a server-side implementation of the Flux pattern.




回答2:


We do use the flux pattern on the client side without having node.js installed on our web servers. In order to do this we have to use Node.js at build time on our Team City CI servers to run a gulp task that pushes the .jsx files through the jsx interpreters and spit out a raw js file. Now our flux application is a essentially a static .js file that has already been interpreted by Node.js



来源:https://stackoverflow.com/questions/31599992/how-to-use-flux-and-event-emitter-with-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!