Skip to content

Commit 5bace57

Browse files
imyzfHanks10100
authored andcommitted
change vRef to ref and delete _update_slot (#10)
* feat(weex): publish weex-vue-framework 2.5.16-weex.1 * feat(weex): change vRef to ref * feat(weex): remove _update_slot event * fix(weex): add '[[VirtualElement]]': true
1 parent 019f0cc commit 5bace57

File tree

5 files changed

+92
-30
lines changed

5 files changed

+92
-30
lines changed

flow/weex.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ declare type WeexCompiledResult = CompiledResult & {
124124
declare type WeexVirtalElement = {
125125
attrs: Object;
126126
type: string;
127-
vRef: string;
127+
ref: string;
128+
'[[VirtualElement]]': true;
128129
}
129130

130131
declare type WeexComponentHookInstance = {

packages/weex-vue-framework/factory.js

Lines changed: 87 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4121,6 +4121,55 @@ function updateComponentData (
41214121
warn(("Failed to update component data (" + componentId + ")."));
41224122
}
41234123

4124+
function updateVirtualRef (vm, refsMap, isRemoval) {
4125+
if (!isObject(refsMap)) { return }
4126+
4127+
if (isRemoval) {
4128+
vm.$refs = {};
4129+
} else {
4130+
var vmRef = vm.$refs || {};
4131+
Object.keys(refsMap).forEach(function (key) {
4132+
var refs = refsMap[key];
4133+
vmRef[key] = refs.length === 1 ? refs[0] : refs;
4134+
});
4135+
vm.$refs = vmRef;
4136+
}
4137+
}
4138+
4139+
function registerListRef (vm, position, refsMap, isRemoval) {
4140+
if (!isObject(refsMap)) { return }
4141+
4142+
var vmRef = vm.$refs || {};
4143+
if (isRemoval) {
4144+
Object.keys(refsMap).forEach(function (key) {
4145+
var refs = refsMap[key];
4146+
4147+
if (vmRef[key]) {
4148+
if (refs.length === 1 && Array.isArray(vmRef[key])) {
4149+
delete vmRef[key][position];
4150+
} else {
4151+
delete vmRef[key];
4152+
}
4153+
}
4154+
});
4155+
} else {
4156+
Object.keys(refsMap).forEach(function (key) {
4157+
var refs = refsMap[key];
4158+
4159+
if (refs.length === 1) {
4160+
if (!Array.isArray(vmRef[key])) {
4161+
vmRef[key] = [];
4162+
}
4163+
// $flow-disable-line
4164+
vmRef[key][position] = refs[0];
4165+
} else {
4166+
vmRef[key] = refs;
4167+
}
4168+
});
4169+
vm.$refs = vmRef;
4170+
}
4171+
}
4172+
41244173
/* */
41254174

41264175
// https://github.com/Hanks10100/weex-native-directive/tree/master/component
@@ -4188,22 +4237,27 @@ function initVirtualComponent (options) {
41884237
initProvide(vm); // resolve provide after data/props
41894238
callHook(vm, 'created');
41904239

4191-
registerComponentHook(componentId, 'lifecycle', 'attach', function () {
4192-
callHook(vm, 'beforeMount');
4240+
registerComponentHook(componentId, 'lifecycle', 'attach',
4241+
function (instance) {
4242+
updateVirtualRef(vm, instance && instance.refs);
41934243

4194-
new Watcher(
4195-
vm,
4196-
function () { return getComponentState(vm); },
4197-
function () { return vm._update(vm._vnode, false); }
4198-
);
4244+
callHook(vm, 'beforeMount');
41994245

4200-
vm._isMounted = true;
4201-
callHook(vm, 'mounted');
4202-
});
4246+
new Watcher(
4247+
vm,
4248+
function () { return getComponentState(vm); },
4249+
function () { return vm._update(vm._vnode, false); }
4250+
);
42034251

4204-
registerComponentHook(componentId, 'lifecycle', 'update', function () {
4205-
vm._update(vm._vnode, false);
4206-
});
4252+
vm._isMounted = true;
4253+
callHook(vm, 'mounted');
4254+
});
4255+
4256+
registerComponentHook(componentId, 'lifecycle', 'update',
4257+
function (instance) {
4258+
updateVirtualRef(vm, instance && instance.refs);
4259+
vm._update(vm._vnode, false);
4260+
});
42074261

42084262
registerComponentHook(
42094263
componentId,
@@ -4219,14 +4273,16 @@ function initVirtualComponent (options) {
42194273
}
42204274
);
42214275

4222-
registerComponentHook(componentId, 'lifecycle', 'detach', function () {
4223-
vm.$destroy();
4224-
if (vm._vmTemplate) {
4276+
registerComponentHook(componentId, 'lifecycle', 'detach',
4277+
function (instance) {
4278+
updateVirtualRef(vm, instance && instance.refs, true);
4279+
vm.$destroy();
4280+
if (vm._vmTemplate) {
42254281
// $flow-disable-line
4226-
vm._vmTemplate.removeVirtualComponent(vm._uid);
4227-
delete vm._vmTemplate;
4228-
}
4229-
});
4282+
vm._vmTemplate.removeVirtualComponent(vm._uid);
4283+
delete vm._vmTemplate;
4284+
}
4285+
});
42304286
}
42314287

42324288
// override Vue.prototype._update
@@ -7214,6 +7270,16 @@ var RecycleList = {
72147270
});
72157271
}
72167272

7273+
this._events['_attach_slot'] = function (instance) {
7274+
registerListRef(this$1.$parent || this$1, instance.position, instance.refs);
7275+
};
7276+
this._events['_update_slot'] = function (instance) {
7277+
registerListRef(this$1.$parent || this$1, instance.position, instance.refs);
7278+
};
7279+
this._events['_detach_slot'] = function (instance) {
7280+
registerListRef(this$1.$parent || this$1, instance.position, instance.refs, true);
7281+
};
7282+
72177283
return h('weex:recycle-list', {
72187284
on: this._events
72197285
}, this.$slots.default)
@@ -7682,7 +7748,7 @@ var canBeLeftOpenTag = makeMap(
76827748
);
76837749

76847750
var isRuntimeComponent = makeMap(
7685-
'richtext,transition,transition-group',
7751+
'richtext,transition,transition-group,recycle-list',
76867752
true
76877753
);
76887754

packages/weex-vue-framework/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "weex-vue-framework",
3-
"version": "2.5.16-weex.0",
3+
"version": "2.5.16-weex.1",
44
"description": "Vue 2.0 Framework for Weex",
55
"main": "index.js",
66
"repository": {

src/platforms/weex/runtime/components/recycle-list.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ export default {
113113
this._events['_attach_slot'] = (instance: WeexComponentHookInstance) => {
114114
registerListRef(this.$parent || this, instance.position, instance.refs)
115115
}
116-
this._events['_update_slot'] = (instance: WeexComponentHookInstance) => {
117-
registerListRef(this.$parent || this, instance.position, instance.refs)
118-
}
119116
this._events['_detach_slot'] = (instance: WeexComponentHookInstance) => {
120117
registerListRef(this.$parent || this, instance.position, instance.refs, true)
121118
}

test/weex/helpers/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ function omitUseless (object, parentKey) {
130130
}
131131
if (key === 'event' && Array.isArray(object[key])) {
132132
object.event = object.event.filter(name => {
133-
return name !== '_attach_slot' && name !== '_update_slot' &&
134-
name !== '_detach_slot'
133+
return name !== '_attach_slot' && name !== '_detach_slot'
135134
})
136135
if (!object.event.length) {
137136
delete object.event
@@ -153,8 +152,7 @@ export function getEvents (instance) {
153152
if (!node) { return }
154153
if (Array.isArray(node.event)) {
155154
node.event.forEach(type => {
156-
if (type !== '_attach_slot' && type !== '_update_slot' &&
157-
type !== '_detach_slot') {
155+
if (type !== '_attach_slot' && type !== '_detach_slot') {
158156
events.push({ ref: node.ref, type })
159157
}
160158
})

0 commit comments

Comments
 (0)