zoukankan      html  css  js  c++  java
  • What is Flux?

    Pluralsight - React and Flux for Angular Developers

    1. An architectural concept. It a idea.

    2. Not a library.

    Key Thinking

    • One way data flow.
    • Events emmiters and dispatchers.

    Javascript Events emmiter

    • Fake events.Really just a arrays of function.
    • Not browser events.

    Emmiter idea code:

    function EventEmmiter(){
        this._events = {};
    }
    
    EventEmmiter.prototype.on = function(type, listener){
        this._events[type] = this._events[type] || [];
        this._events[type].push(listener);
    }
    
    EventEmmiter.prototype.emit = function(type){
        if(this._events[type]){
            this._events[type].forEach(function(listener){
                listener();
            });
        }
    }
    
    EventEmmiter.prototype.removeListener = function(type, listener){
        if(this._events[type]){
            this._events[type].splice(this._events[type].indexOf(listener), 1);
        } 
    }
    

    Dispatcher in javascript

    • Fake event listening. More objects and functions.
    • Functions that respond to particular actions.

    Dispatcher idea code:

    function Dispatcher(){
        this._lastID = 0;
        this._callbacks = {};
    }
    
    Dispatcher.prototype.register = function(callback){
        var id = 'CID_' + this._lastID++;
        this._callback[id] = callback;
    }
    
    Dispatcher.prototype.dispatch = function(action){
        for(var id in this._callback){
            this._callbacks[id](action);
        }
    }
    
    Dispatcher.prototype.waitFor = function(ids){
        //TODO
    }
    

    One way data flow


    Two way data flow


  • 相关阅读:
    Direct2D教程(二)来看D2D世界中的Hello,World
    绕任意轴旋转
    XPDM vs WDDM
    也谈杨辉三角形
    用DirectX实现粒子系统(一)
    Alpha混合(一)Vertex Alpha
    几何变换详解
    用DirectX实现粒子系统(三)
    Alpha混合(二)Material Alpha
    Direct2D教程(五)复合图形
  • 原文地址:https://www.cnblogs.com/skating/p/6169000.html
Copyright © 2011-2022 走看看