weex-vue-framework
Advanced tools
Comparing version 2.5.4-weex.0 to 2.5.4-weex-es6.0
90
index.js
@@ -6,5 +6,5 @@ 'use strict'; | ||
// this will be preserved during build | ||
var VueFactory = require('./factory'); | ||
const VueFactory = require('./factory'); | ||
var instances = {}; | ||
const instances = {}; | ||
@@ -15,3 +15,3 @@ /** | ||
function reset () { | ||
for (var key in instances) { | ||
for (const key in instances) { | ||
delete instances[key]; | ||
@@ -21,9 +21,7 @@ } | ||
function createInstanceContext (instanceId, runtimeContext, data) { | ||
if ( runtimeContext === void 0 ) runtimeContext = {}; | ||
var weex = runtimeContext.weex; | ||
var instance = instances[instanceId] = { | ||
instanceId: instanceId, | ||
data: data, | ||
function createInstanceContext (instanceId, runtimeContext = {}, data) { | ||
const weex = runtimeContext.weex; | ||
const instance = instances[instanceId] = { | ||
instanceId, | ||
data, | ||
document: weex.document | ||
@@ -33,6 +31,6 @@ }; | ||
// Each instance has a independent `Vue` module instance | ||
var Vue = instance.Vue = createVueModuleInstance(instanceId, weex); | ||
const Vue = instance.Vue = createVueModuleInstance(instanceId, weex); | ||
var timerAPIs = getInstanceTimer(instanceId, weex.requireModule); | ||
var instanceContext = Object.assign({ Vue: Vue }, timerAPIs); | ||
const timerAPIs = getInstanceTimer(instanceId, weex.requireModule); | ||
const instanceContext = Object.assign({ Vue }, timerAPIs); | ||
Object.freeze(instanceContext); | ||
@@ -49,3 +47,3 @@ | ||
function destroyInstance (instanceId) { | ||
var instance = instances[instanceId]; | ||
const instance = instances[instanceId]; | ||
if (instance && instance.app instanceof instance.Vue) { | ||
@@ -68,7 +66,7 @@ instance.document.destroy(); | ||
function refreshInstance (instanceId, data) { | ||
var instance = instances[instanceId]; | ||
const instance = instances[instanceId]; | ||
if (!instance || !(instance.app instanceof instance.Vue)) { | ||
return new Error(("refreshInstance: instance " + instanceId + " not found!")) | ||
return new Error(`refreshInstance: instance ${instanceId} not found!`) | ||
} | ||
for (var key in data) { | ||
for (const key in data) { | ||
instance.Vue.set(instance.app, key, data[key]); | ||
@@ -84,19 +82,19 @@ } | ||
function createVueModuleInstance (instanceId, weex) { | ||
var exports = {}; | ||
const exports = {}; | ||
VueFactory(exports, weex.document); | ||
var Vue = exports.Vue; | ||
const Vue = exports.Vue; | ||
var instance = instances[instanceId]; | ||
const instance = instances[instanceId]; | ||
// patch reserved tag detection to account for dynamically registered | ||
// components | ||
var weexRegex = /^weex:/i; | ||
var isReservedTag = Vue.config.isReservedTag || (function () { return false; }); | ||
var isRuntimeComponent = Vue.config.isRuntimeComponent || (function () { return false; }); | ||
Vue.config.isReservedTag = function (name) { | ||
return (!isRuntimeComponent(name) && weex.supports(("@component/" + name))) || | ||
const weexRegex = /^weex:/i; | ||
const isReservedTag = Vue.config.isReservedTag || (() => false); | ||
const isRuntimeComponent = Vue.config.isRuntimeComponent || (() => false); | ||
Vue.config.isReservedTag = name => { | ||
return (!isRuntimeComponent(name) && weex.supports(`@component/${name}`)) || | ||
isReservedTag(name) || | ||
weexRegex.test(name) | ||
}; | ||
Vue.config.parsePlatformTagName = function (name) { return name.replace(weexRegex, ''); }; | ||
Vue.config.parsePlatformTagName = name => name.replace(weexRegex, ''); | ||
@@ -113,9 +111,9 @@ // expose weex-specific info | ||
Vue.mixin({ | ||
beforeCreate: function beforeCreate () { | ||
var options = this.$options; | ||
beforeCreate () { | ||
const options = this.$options; | ||
// root component (vm) | ||
if (options.el) { | ||
// set external data of instance | ||
var dataOption = options.data; | ||
var internalData = (typeof dataOption === 'function' ? dataOption() : dataOption) || {}; | ||
const dataOption = options.data; | ||
const internalData = (typeof dataOption === 'function' ? dataOption() : dataOption) || {}; | ||
options.data = Object.assign(internalData, instance.data); | ||
@@ -126,4 +124,4 @@ // record instance by id | ||
}, | ||
mounted: function mounted () { | ||
var options = this.$options; | ||
mounted () { | ||
const options = this.$options; | ||
// root component (vm) | ||
@@ -152,11 +150,8 @@ if (options.el && weex.document && instance.app === this) { | ||
function getInstanceTimer (instanceId, moduleGetter) { | ||
var instance = instances[instanceId]; | ||
var timer = moduleGetter('timer'); | ||
var timerAPIs = { | ||
setTimeout: function () { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
var handler = function () { | ||
args[0].apply(args, args.slice(2)); | ||
const instance = instances[instanceId]; | ||
const timer = moduleGetter('timer'); | ||
const timerAPIs = { | ||
setTimeout: (...args) => { | ||
const handler = function () { | ||
args[0](...args.slice(2)); | ||
}; | ||
@@ -167,8 +162,5 @@ | ||
}, | ||
setInterval: function () { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
var handler = function () { | ||
args[0].apply(args, args.slice(2)); | ||
setInterval: (...args) => { | ||
const handler = function () { | ||
args[0](...args.slice(2)); | ||
}; | ||
@@ -179,6 +171,6 @@ | ||
}, | ||
clearTimeout: function (n) { | ||
clearTimeout: (n) => { | ||
timer.clearTimeout(n); | ||
}, | ||
clearInterval: function (n) { | ||
clearInterval: (n) => { | ||
timer.clearInterval(n); | ||
@@ -185,0 +177,0 @@ } |
{ | ||
"name": "weex-vue-framework", | ||
"version": "2.5.4-weex.0", | ||
"version": "2.5.4-weex-es6.0", | ||
"description": "Vue 2.0 Framework for Weex", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
190636
6540