• 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


  • 相关阅读:
    web前段知识
    如何查看服务器机型,如何查看软件的版本信息
    selenium server启动失败
    性能测试策略
    mysql_列出表中所有字段用逗号做分隔符
    复杂sql(1)
    orale建表查询
    javascript常用函数集
    orale用户角色管理
    数据流
  • 原文地址:https://www.cnblogs.com/skating/p/6169000.html
Copyright © 2020-2023  润新知