weex-vue-framework
Advanced tools
Comparing version 2.5.4-weex-es6.0 to 2.5.11-weex.0
158
index.js
@@ -5,31 +5,38 @@ 'use strict'; | ||
/* */ | ||
// this will be preserved during build | ||
const VueFactory = require('./factory'); | ||
// $flow-disable-line | ||
var VueFactory = require('./factory'); | ||
const instances = {}; | ||
var instanceOptions = {}; | ||
/** | ||
* Reset framework config and clear all registrations. | ||
* Create instance context. | ||
*/ | ||
function reset () { | ||
for (const key in instances) { | ||
delete instances[key]; | ||
} | ||
} | ||
function createInstanceContext ( | ||
instanceId, | ||
runtimeContext, | ||
data | ||
) { | ||
if ( data === void 0 ) data = {}; | ||
function createInstanceContext (instanceId, runtimeContext = {}, data) { | ||
const weex = runtimeContext.weex; | ||
const instance = instances[instanceId] = { | ||
instanceId, | ||
data, | ||
document: weex.document | ||
var weex = runtimeContext.weex; | ||
var instance = instanceOptions[instanceId] = { | ||
instanceId: instanceId, | ||
config: weex.config, | ||
document: weex.document, | ||
data: data | ||
}; | ||
// Each instance has a independent `Vue` module instance | ||
const Vue = instance.Vue = createVueModuleInstance(instanceId, weex); | ||
var Vue = instance.Vue = createVueModuleInstance(instanceId, weex); | ||
var proto = Object.getPrototypeOf(Vue); | ||
Object.freeze(proto); | ||
const timerAPIs = getInstanceTimer(instanceId, weex.requireModule); | ||
const instanceContext = Object.assign({ Vue }, timerAPIs); | ||
// DEPRECATED | ||
var timerAPIs = getInstanceTimer(instanceId, weex.requireModule); | ||
var instanceContext = Object.assign({ Vue: Vue }, timerAPIs); | ||
Object.freeze(instanceContext); | ||
return instanceContext | ||
@@ -41,13 +48,14 @@ } | ||
* this instance released and no more leaks. | ||
* @param {string} instanceId | ||
*/ | ||
function destroyInstance (instanceId) { | ||
const instance = instances[instanceId]; | ||
var instance = instanceOptions[instanceId]; | ||
if (instance && instance.app instanceof instance.Vue) { | ||
instance.document.destroy(); | ||
instance.app.$destroy(); | ||
try { | ||
instance.app.$destroy(); | ||
instance.document.destroy(); | ||
} catch (e) {} | ||
delete instance.document; | ||
delete instance.app; | ||
} | ||
delete instances[instanceId]; | ||
delete instanceOptions[instanceId]; | ||
} | ||
@@ -59,12 +67,15 @@ | ||
* define all possible meaningful keys when instance created. | ||
* @param {string} instanceId | ||
* @param {object} data | ||
*/ | ||
function refreshInstance (instanceId, data) { | ||
const instance = instances[instanceId]; | ||
function refreshInstance ( | ||
instanceId, | ||
data | ||
) { | ||
var instance = instanceOptions[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 (const key in data) { | ||
instance.Vue.set(instance.app, key, data[key]); | ||
if (instance.Vue && instance.Vue.set) { | ||
for (var key in data) { | ||
instance.Vue.set(instance.app, key, data[key]); | ||
} | ||
} | ||
@@ -78,23 +89,27 @@ // Finally `refreshFinish` signal needed. | ||
*/ | ||
function createVueModuleInstance (instanceId, weex) { | ||
const exports = {}; | ||
function createVueModuleInstance ( | ||
instanceId, | ||
weex | ||
) { | ||
var exports = {}; | ||
VueFactory(exports, weex.document); | ||
const Vue = exports.Vue; | ||
var Vue = exports.Vue; | ||
const instance = instances[instanceId]; | ||
var instance = instanceOptions[instanceId]; | ||
// patch reserved tag detection to account for dynamically registered | ||
// components | ||
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}`)) || | ||
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))) || | ||
isReservedTag(name) || | ||
weexRegex.test(name) | ||
}; | ||
Vue.config.parsePlatformTagName = name => name.replace(weexRegex, ''); | ||
Vue.config.parsePlatformTagName = function (name) { return name.replace(weexRegex, ''); }; | ||
// expose weex-specific info | ||
Vue.prototype.$instanceId = instanceId; | ||
Vue.prototype.$document = instance.document; | ||
@@ -108,9 +123,9 @@ // expose weex native module getter on subVue prototype so that | ||
Vue.mixin({ | ||
beforeCreate () { | ||
const options = this.$options; | ||
beforeCreate: function beforeCreate () { | ||
var options = this.$options; | ||
// root component (vm) | ||
if (options.el) { | ||
// set external data of instance | ||
const dataOption = options.data; | ||
const internalData = (typeof dataOption === 'function' ? dataOption() : dataOption) || {}; | ||
var dataOption = options.data; | ||
var internalData = (typeof dataOption === 'function' ? dataOption() : dataOption) || {}; | ||
options.data = Object.assign(internalData, instance.data); | ||
@@ -121,8 +136,8 @@ // record instance by id | ||
}, | ||
mounted () { | ||
const options = this.$options; | ||
mounted: function mounted () { | ||
var options = this.$options; | ||
// root component (vm) | ||
if (options.el && weex.document && instance.app === this) { | ||
try { | ||
// Send `createFinish` signal to native. | ||
// Send "createFinish" signal to native. | ||
weex.document.taskCenter.send('dom', { action: 'createFinish' }, []); | ||
@@ -134,2 +149,13 @@ } catch (e) {} | ||
/** | ||
* @deprecated Just instance variable `weex.config` | ||
* Get instance config. | ||
* @return {object} | ||
*/ | ||
Vue.prototype.$getConfig = function () { | ||
if (instance.app instanceof Vue) { | ||
return instance.config | ||
} | ||
}; | ||
return Vue | ||
@@ -139,2 +165,3 @@ } | ||
/** | ||
* DEPRECATED | ||
* Generate HTML5 Timer APIs. An important point is that the callback | ||
@@ -144,13 +171,16 @@ * will be converted into callback id when sent to native. So the | ||
* an instance destroyed. | ||
* @param {[type]} instanceId [description] | ||
* @param {[type]} moduleGetter [description] | ||
* @return {[type]} [description] | ||
*/ | ||
function getInstanceTimer (instanceId, moduleGetter) { | ||
const instance = instances[instanceId]; | ||
const timer = moduleGetter('timer'); | ||
const timerAPIs = { | ||
setTimeout: (...args) => { | ||
const handler = function () { | ||
args[0](...args.slice(2)); | ||
function getInstanceTimer ( | ||
instanceId, | ||
moduleGetter | ||
) { | ||
var instance = instanceOptions[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)); | ||
}; | ||
@@ -161,5 +191,8 @@ | ||
}, | ||
setInterval: (...args) => { | ||
const handler = function () { | ||
args[0](...args.slice(2)); | ||
setInterval: function () { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
var handler = function () { | ||
args[0].apply(args, args.slice(2)); | ||
}; | ||
@@ -170,6 +203,6 @@ | ||
}, | ||
clearTimeout: (n) => { | ||
clearTimeout: function (n) { | ||
timer.clearTimeout(n); | ||
}, | ||
clearInterval: (n) => { | ||
clearInterval: function (n) { | ||
timer.clearInterval(n); | ||
@@ -181,5 +214,4 @@ } | ||
exports.reset = reset; | ||
exports.createInstanceContext = createInstanceContext; | ||
exports.destroyInstance = destroyInstance; | ||
exports.refreshInstance = refreshInstance; |
{ | ||
"name": "weex-vue-framework", | ||
"version": "2.5.4-weex-es6.0", | ||
"version": "2.5.11-weex.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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
399124
6
13664