UNPKG

3.37 kBJavaScriptView Raw
1'use strict';
2
3exports.__esModule = true;
4exports.page = page;
5
6function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
7
8//export {binding} from './valuelink'
9
10var _extend = require('extend');
11
12var _extend2 = _interopRequireDefault(_extend);
13
14var _gfsReactTools = require('gfs-react-tools');
15
16var _gfsReactTools2 = _interopRequireDefault(_gfsReactTools);
17
18var _model = require('./model');
19
20var _reduxThunk = require('redux-thunk');
21
22var _reduxThunk2 = _interopRequireDefault(_reduxThunk);
23
24var _immutable = require('immutable');
25
26var _immutable2 = _interopRequireDefault(_immutable);
27
28exports.Model = _model.Model;
29
30var _control = require('./control');
31
32exports.Control = _control.Control;
33exports.Sync = _control.Sync;
34exports.fetch = _control.fetch;
35
36var _view = require('./view');
37
38exports.View = _view.View;
39
40var _decorator = require('./decorator');
41
42exports.Action = _decorator.enumerable;
43exports.Noenumerable = _decorator.noenumerable;
44
45if (window && window.DM_STORE) {
46 var __initData = {},
47 dmStore = window.DM_STORE;
48 for (var item in dmStore) {
49 if (dmStore[item] instanceof Object) {
50 __initData[item] = _immutable2['default'].fromJS(dmStore[item]);
51 }
52 }
53 window.DM_STORE = __initData;
54}
55
56/**
57 * 提供Model、View、Control、Sync、RTools等系列便捷类库
58 * @module gfs-react-mvc
59 * */
60
61/**
62 * 页面渲染
63 * @class Page
64 * */
65
66/**
67 *
68 * @method page
69 * @param opts {object} 可以直接等于react component
70 * @param opts.middleware {array} 可选,中间件集合
71 * @param opts.module {react component} 必填,需要渲染在页面的组件
72 * @param opts.devTools {object} 可选,数据模型调试,可视化面板,可以查看数据模型结构
73 * @param opts.bar {object} 可选,异步数据请求时加载状态栏
74* @param opts.debug {Boolean} 可选,是否是调试状态,调试状态下会输出日志信息
75 * @param opts.agent {string} 可选,默认值为pc,三种可选值:pc、wap、other,other已bar字段对象为准
76 * @param opts.container {string} 可选,默认为root,组件放在页面的容器id
77 * @return RTools
78 * @example
79 *
80 * imoprt {page} from 'gfs-react-mvc'
81 * import Module from './TestComponent'
82 *
83 * //渲染到页面
84 * page(Module)
85 * */
86
87function page() {
88 var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
89
90 if (opts && typeof opts.module === 'undefined') {
91 opts = {
92 module: opts
93 };
94 }
95
96 opts.middleware = [_reduxThunk2['default']].concat(opts.middleware || []);
97
98 if (opts.debug || typeof opts.debug == 'undefined' && location && location.port != '') {
99 opts.middleware.push(require('redux-logger')());
100 }
101
102 var rtools = new _gfsReactTools2['default'](_extend2['default']({
103 //可选
104 middleware: [],
105 //必填
106 module: null,
107 //可选
108 reducers: _model.getModels(),
109 //可选n
110 //devTools:DevTools,
111 //可选 默认loadingbarComponent
112 //bar:null,
113 //可选 loadingbar平台(pc/wap/other)other直接使用bar字段作为参数
114 //agent:'pc',
115 //可选 react component放取的节点id
116 container: 'root',
117 debug: false
118 }, opts));
119
120 // emptyModels()
121
122 return rtools;
123}
\No newline at end of file