张延森 4 years ago
parent
commit
169ca63102
1 changed files with 11 additions and 1 deletions
  1. 11
    1
      src/utils/store/executor.js

+ 11
- 1
src/utils/store/executor.js View File

19
 
19
 
20
 const noop = () => undefined
20
 const noop = () => undefined
21
 
21
 
22
+const entries = obj => {
23
+  const ownProps = Object.keys( obj )
24
+  let i = ownProps.length
25
+  const resArray = new Array(i)
26
+  while (i--)
27
+    resArray[i] = [ownProps[i], obj[ownProps[i]]]
28
+
29
+  return resArray
30
+}
31
+
22
 // 所有的 Model 会分别被绑定到各自 Executor 上
32
 // 所有的 Model 会分别被绑定到各自 Executor 上
23
 // 借用 Executor onUpdate 把 Model 的变化传递到各订阅的组件上
33
 // 借用 Executor onUpdate 把 Model 的变化传递到各订阅的组件上
24
 export function Executor(props) {
34
 export function Executor(props) {
53
     return (
63
     return (
54
       <>
64
       <>
55
       {
65
       {
56
-        Object.entries(models).map(pair => {
66
+        entries(models).map(pair => {
57
           const [namespace, hook] = pair
67
           const [namespace, hook] = pair
58
           return <Executor key={namespace} namespace={namespace} model={hook} store={store} />
68
           return <Executor key={namespace} namespace={namespace} model={hook} store={store} />
59
         })
69
         })