Code coverage report for lib/component/ConextProvider.js

Statements: 100% (6 / 6)      Branches: 100% (0 / 0)      Functions: 100% (2 / 2)      Lines: 100% (6 / 6)      Ignored: none     

All files » lib/component/ » ConextProvider.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80              1                             1                                                             4                         4   4                   1  
/**
 * @file ContextProvider
 *
 * @author Leon(leon@outlook.com)
 * @requires react
 */
 
var React = require('react');
 
/**
 * ei上下文提供组件
 *
 *
 * 此模块主要用于提供React组件的`context`环境
 * 凡在`ContextProvider`中的组件,都可以通过向`contextTypes`添加`ei`属性来获得`context`的访问权限
 *
 * 在`ei`属性中,我们提供了`store`和`dispatch`两个接口
 * 分别用来获取`store`数据和发送`action`
 *
 * @class
 * @extends ReactComponent
 */
var ContextProvider = React.createClass(/** @lends ContextProvider.prototype */ {
 
 
    /**
     * 子控件上下文属性类型描述符
     *
     * @type {Object}
     */
    childContextTypes: {
        ei: React.PropTypes.object.isRequired
    },
 
    /**
     * `ContextProvider`实例化参数类型描述符
     *
     * `ContextProvider`组件必须包含有一个ei属性
     *
     * @type {Object}
     */
    propTypes: {
        ei: React.PropTypes.object.isRequired
    },
 
    /**
     * 获取子控件上下文
     *
     * @protected
     * @return {Object}
     */
    getChildContext: function () {
 
        return {
            ei: this.props.ei
        };
 
    },
 
    /**
     * 渲染
     *
     * @return {ReactElement}
     */
    render: function () {
 
        var ei = this.props.ei;
 
        return this.props.children(
            ei.store,
            ei.dispatch
        );
 
    }
 
 
});
 
module.exports = ContextProvider;