Skip to content

Commit cbbc4ce

Browse files
author
Iftekhar Rifat
committed
Use render function instead of template
This is needed for runtime only environment in Vue
1 parent 30a0c11 commit cbbc4ce

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/connect.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,32 @@ export default function connect(mapStateAsProps = noop, mapActionsAsProps = noop
77
return (children) => {
88
const props = children.props || {};
99
const subscriptions = children.collect || {};
10-
10+
1111
const allProps = {
1212
...normalizeProps(props),
1313
...normalizeProps(subscriptions)
1414
};
1515

16-
17-
const propsToPass = Object.keys(allProps).map(key => `:${key}='${key}'`).join(' ');
18-
const template = `<children ${propsToPass}></children>`;
19-
2016
children.props = allProps;
2117
delete children.collect;
2218

2319
return {
24-
template,
20+
name: 'VuaRedux',
21+
2522
props: props,
2623

24+
render(h) {
25+
const keys = Object.keys(allProps);
26+
let propsToPass = {};
27+
for (let i = 0; i < keys.length; i++) {
28+
propsToPass[keys[i]] = this[keys[i]];
29+
}
30+
31+
return h(children, {
32+
props: propsToPass
33+
})
34+
},
35+
2736
data() {
2837
const store = this.$store;
2938
const state = mapStateAsProps(store.getState()) || {};
@@ -35,10 +44,6 @@ export default function connect(mapStateAsProps = noop, mapActionsAsProps = noop
3544
};
3645
},
3746

38-
components: {
39-
children
40-
},
41-
4247
created() {
4348
const store = this.$store;
4449
const state = mapStateAsProps(store.getState()) || {};
@@ -47,9 +52,9 @@ export default function connect(mapStateAsProps = noop, mapActionsAsProps = noop
4752
this.unsubscribe = store.subscribe(() => {
4853
const state = mapStateAsProps(store.getState());
4954

50-
stateNames.forEach((key) => { // fixme: use a simple loop
51-
this[key] = state[key];
52-
});
55+
for (let i = 0; i < stateNames.length; i++) {
56+
this[stateNames[i]] = state[stateNames[i]];
57+
}
5358
});
5459
},
5560

0 commit comments

Comments
 (0)