You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@weex.apache.org by yong-chen04 <gi...@git.apache.org> on 2017/03/17 11:18:58 UTC
[GitHub] incubator-weex pull request #126: Jsfm feature vanilla
GitHub user yong-chen04 opened a pull request:
https://github.com/apache/incubator-weex/pull/126
Jsfm feature vanilla
Previous conversations http://mail-archives.apache.org/mod_mbox/incubator-weex-dev/201703.mbox/browser
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/yong-chen04/incubator-weex jsfm-feature-vanilla
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-weex/pull/126.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #126
----
commit 12050c4e4c4735d2ef0e7f3a803ddd9bd1bf6450
Author: ChenYong <yo...@ele.me>
Date: 2017-03-10T08:45:31Z
* [html5] update Vanilla framework with code from Vue
commit 7f6abe0c6aef94e28a40fac813d1e3ba7d59f2cf
Author: ChenYong <yo...@ele.me>
Date: 2017-03-15T08:18:59Z
* [html5] update vanilla example
commit 0f119ec5398fea167570b2b88e1aed8732aa5601
Author: ChenYong <yo...@ele.me>
Date: 2017-03-17T10:50:05Z
* [html5] vanilla test updates
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-weex issue #126: Jsfm feature vanilla
Posted by yong-chen04 <gi...@git.apache.org>.
Github user yong-chen04 commented on the issue:
https://github.com/apache/incubator-weex/pull/126
I still got some errors after running the test, do you know how to fix this one(appeared 3 times):
```
273 passing (751ms)
61 pending
3 failing
1) vanilla test create & destroy instance:
TypeError: Function.prototype.apply was called on undefined, which is a undefined and not a function
at Object.sendTasks (html5/runtime/config.js:9:19)
at Object.createInstance (html5/frameworks/vanilla/index.js:103:12)
at Context.it (html5/test/unit/vanilla/index.js:35:13)
2) vanilla test getRoot:
TypeError: Function.prototype.apply was called on undefined, which is a undefined and not a function
at Object.sendTasks (html5/runtime/config.js:9:19)
at Object.createInstance (html5/frameworks/vanilla/index.js:103:12)
at Context.it (html5/test/unit/vanilla/index.js:55:13)
3) vanilla test receiveTasks "before all" hook for "getRoot":
TypeError: Function.prototype.apply was called on undefined, which is a undefined and not a function
at Object.sendTasks (html5/runtime/config.js:9:19)
at Object.createInstance (html5/frameworks/vanilla/index.js:103:12)
at Context.before (html5/test/unit/vanilla/index.js:94:15)
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-weex issue #126: Jsfm feature vanilla
Posted by yong-chen04 <gi...@git.apache.org>.
Github user yong-chen04 commented on the issue:
https://github.com/apache/incubator-weex/pull/126
Updated.
Well, I thought you still writing `else` in that old way...
https://github.com/apache/incubator-weex/blob/master/html5/render/browser/extend/components/scrollable/scroll.js#L68
https://github.com/apache/incubator-weex/blob/master/examples/vue/showcase/include/util.js#L59
https://github.com/apache/incubator-weex/blob/dev/build/webpack.test.config.js#L17
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-weex pull request #126: Jsfm feature vanilla
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/incubator-weex/pull/126
---
[GitHub] incubator-weex pull request #126: Jsfm feature vanilla
Posted by jiyinyiyong <gi...@git.apache.org>.
Github user jiyinyiyong commented on a diff in the pull request:
https://github.com/apache/incubator-weex/pull/126#discussion_r106771723
--- Diff: html5/frameworks/vanilla/index.js ---
@@ -1,107 +1,334 @@
-const config = {}
-const instanceMap = {}
+const instances = {}
+const modules = {}
+const components = {}
-function init (cfg) {
- config.Document = cfg.Document
- config.Element = cfg.Element
- config.Comment = cfg.Comment
- config.sendTasks = cfg.sendTasks
+const renderer = {
+ instances,
+ modules,
+ components
}
-function registerComponents (components) {}
+/**
+ * Prepare framework config, basically about the virtual-DOM and JS bridge.
+ * @param {object} cfg
+ */
+export function init (cfg) {
+ renderer.Document = cfg.Document
+ renderer.Element = cfg.Element
+ renderer.Comment = cfg.Comment
+ renderer.sendTasks = cfg.sendTasks
+}
-function registerModules (modules) {}
+/**
+ * Reset framework config and clear all registrations.
+ */
+export function reset () {
+ clear(instances)
+ clear(modules)
+ clear(components)
+ delete renderer.Document
+ delete renderer.Element
+ delete renderer.Comment
+ delete renderer.sendTasks
+}
-function registerMethods (apis) {}
+/**
+ * Delete all keys of an object.
+ * @param {object} obj
+ */
+function clear (obj) {
+ for (const key in obj) {
+ delete obj[key]
+ }
+}
-function prepareInstance (id, options, data) {}
+/**
+ * Create an instance with id, code, config and external data.
+ * @param {string} instanceId
+ * @param {string} appCode
+ * @param {object} config
+ * @param {object} data
+ * @param {object} env { info, config, services }
+ */
+export function createInstance (
+ instanceId,
+ appCode = '',
+ config = {},
+ data,
+ env = {}
+) {
+ // Virtual-DOM object.
+ const document = new renderer.Document(instanceId, config.bundleUrl)
-function createInstance (id, code, options, data, serviceObjects) {
- const document = new config.Document(id, options.bundleUrl)
- const callbacks = {}
+ // All function/callback of parameters before sent to native
+ // will be converted as an id. So `callbacks` is used to store
+ // these real functions. When a callback invoked and won't be
+ // called again, it should be removed from here automatically.
+ const callbacks = []
- let lastCallbackId = 0
- document.addCallback = func => {
- lastCallbackId++
- callbacks[lastCallbackId] = func
- return lastCallbackId
- }
- document.handleCallback = (funcId, data, ifLast) => {
- const callback = callbacks[funcId]
- if (ifLast) {
- delete callbacks[funcId]
- }
- return callback(data)
+ // The latest callback id, incremental.
+ const callbackId = 1
+
+ instances[instanceId] = {
+ instanceId, config, data,
+ document, callbacks, callbackId
}
- instanceMap[id] = document
- const globalObjects = Object.assign({
- Document: config.Document,
- Element: config.Element,
- Comment: config.Comment,
- sendTasks: config.sendTasks,
- id, options, data, document
- }, serviceObjects)
+ // Prepare native module getter and HTML5 Timer APIs.
+ const moduleGetter = genModuleGetter(instanceId)
+ const timerAPIs = getInstanceTimer(instanceId, moduleGetter)
- const globalKeys = []
- const globalValues = []
- for (const key in globalObjects) {
- globalKeys.push(key)
- globalValues.push(globalObjects[key])
+ // Prepare `weex` instance variable.
+ const weexInstanceVar = {
+ config,
+ document,
+ requireModule: moduleGetter
}
- globalKeys.push(code)
+ Object.freeze(weexInstanceVar)
- const result = new Function(...globalKeys)
- return result(...globalValues)
+ // The function which create a closure the JS Bundle will run in.
+ // It will declare some instance variables like HTML5 Timer APIs etc.
+ const instanceVars = Object.assign({
+ weex: weexInstanceVar,
+ // deprecated
+ __weex_require_module__: weexInstanceVar.requireModule // eslint-disable-line
+ }, timerAPIs)
+ callFunction(instanceVars, appCode)
--- End diff --
I can see the benefit of making an object for `global` scope. Any reason why Vue doesn't have one?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-weex pull request #126: Jsfm feature vanilla
Posted by jiyinyiyong <gi...@git.apache.org>.
Github user jiyinyiyong commented on a diff in the pull request:
https://github.com/apache/incubator-weex/pull/126#discussion_r106771757
--- Diff: html5/frameworks/vanilla/index.js ---
@@ -1,107 +1,334 @@
-const config = {}
-const instanceMap = {}
+const instances = {}
+const modules = {}
+const components = {}
-function init (cfg) {
- config.Document = cfg.Document
- config.Element = cfg.Element
- config.Comment = cfg.Comment
- config.sendTasks = cfg.sendTasks
+const renderer = {
+ instances,
+ modules,
+ components
}
-function registerComponents (components) {}
+/**
+ * Prepare framework config, basically about the virtual-DOM and JS bridge.
+ * @param {object} cfg
+ */
+export function init (cfg) {
+ renderer.Document = cfg.Document
+ renderer.Element = cfg.Element
+ renderer.Comment = cfg.Comment
+ renderer.sendTasks = cfg.sendTasks
+}
-function registerModules (modules) {}
+/**
+ * Reset framework config and clear all registrations.
+ */
+export function reset () {
+ clear(instances)
+ clear(modules)
+ clear(components)
+ delete renderer.Document
+ delete renderer.Element
+ delete renderer.Comment
+ delete renderer.sendTasks
+}
-function registerMethods (apis) {}
+/**
+ * Delete all keys of an object.
+ * @param {object} obj
+ */
+function clear (obj) {
+ for (const key in obj) {
+ delete obj[key]
+ }
+}
-function prepareInstance (id, options, data) {}
+/**
+ * Create an instance with id, code, config and external data.
+ * @param {string} instanceId
+ * @param {string} appCode
+ * @param {object} config
+ * @param {object} data
+ * @param {object} env { info, config, services }
+ */
+export function createInstance (
+ instanceId,
+ appCode = '',
+ config = {},
+ data,
+ env = {}
+) {
+ // Virtual-DOM object.
+ const document = new renderer.Document(instanceId, config.bundleUrl)
-function createInstance (id, code, options, data, serviceObjects) {
- const document = new config.Document(id, options.bundleUrl)
- const callbacks = {}
+ // All function/callback of parameters before sent to native
+ // will be converted as an id. So `callbacks` is used to store
+ // these real functions. When a callback invoked and won't be
+ // called again, it should be removed from here automatically.
+ const callbacks = []
- let lastCallbackId = 0
- document.addCallback = func => {
- lastCallbackId++
- callbacks[lastCallbackId] = func
- return lastCallbackId
- }
- document.handleCallback = (funcId, data, ifLast) => {
- const callback = callbacks[funcId]
- if (ifLast) {
- delete callbacks[funcId]
- }
- return callback(data)
+ // The latest callback id, incremental.
+ const callbackId = 1
+
+ instances[instanceId] = {
+ instanceId, config, data,
+ document, callbacks, callbackId
}
- instanceMap[id] = document
- const globalObjects = Object.assign({
- Document: config.Document,
- Element: config.Element,
- Comment: config.Comment,
- sendTasks: config.sendTasks,
- id, options, data, document
- }, serviceObjects)
+ // Prepare native module getter and HTML5 Timer APIs.
+ const moduleGetter = genModuleGetter(instanceId)
+ const timerAPIs = getInstanceTimer(instanceId, moduleGetter)
- const globalKeys = []
- const globalValues = []
- for (const key in globalObjects) {
- globalKeys.push(key)
- globalValues.push(globalObjects[key])
+ // Prepare `weex` instance variable.
+ const weexInstanceVar = {
+ config,
+ document,
+ requireModule: moduleGetter
}
- globalKeys.push(code)
+ Object.freeze(weexInstanceVar)
- const result = new Function(...globalKeys)
- return result(...globalValues)
+ // The function which create a closure the JS Bundle will run in.
+ // It will declare some instance variables like HTML5 Timer APIs etc.
+ const instanceVars = Object.assign({
+ weex: weexInstanceVar,
+ // deprecated
+ __weex_require_module__: weexInstanceVar.requireModule // eslint-disable-line
--- End diff --
Better have one in when people are using it frequently. Will do in Monday, the code is in my laptop at office.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-weex issue #126: Jsfm feature vanilla
Posted by jiyinyiyong <gi...@git.apache.org>.
Github user jiyinyiyong commented on the issue:
https://github.com/apache/incubator-weex/pull/126
@fkysly ping?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-weex issue #126: Jsfm feature vanilla
Posted by jiyinyiyong <gi...@git.apache.org>.
Github user jiyinyiyong commented on the issue:
https://github.com/apache/incubator-weex/pull/126
@Hanks10100 any thoughts on the tests? Can I remove `document.addCallback` from tests?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-weex pull request #126: Jsfm feature vanilla
Posted by Hanks10100 <gi...@git.apache.org>.
Github user Hanks10100 commented on a diff in the pull request:
https://github.com/apache/incubator-weex/pull/126#discussion_r106826163
--- Diff: html5/frameworks/vanilla/index.js ---
@@ -1,107 +1,334 @@
-const config = {}
-const instanceMap = {}
+const instances = {}
+const modules = {}
+const components = {}
-function init (cfg) {
- config.Document = cfg.Document
- config.Element = cfg.Element
- config.Comment = cfg.Comment
- config.sendTasks = cfg.sendTasks
+const renderer = {
+ instances,
+ modules,
+ components
}
-function registerComponents (components) {}
+/**
+ * Prepare framework config, basically about the virtual-DOM and JS bridge.
+ * @param {object} cfg
+ */
+export function init (cfg) {
+ renderer.Document = cfg.Document
+ renderer.Element = cfg.Element
+ renderer.Comment = cfg.Comment
+ renderer.sendTasks = cfg.sendTasks
+}
-function registerModules (modules) {}
+/**
+ * Reset framework config and clear all registrations.
+ */
+export function reset () {
+ clear(instances)
+ clear(modules)
+ clear(components)
+ delete renderer.Document
+ delete renderer.Element
+ delete renderer.Comment
+ delete renderer.sendTasks
+}
-function registerMethods (apis) {}
+/**
+ * Delete all keys of an object.
+ * @param {object} obj
+ */
+function clear (obj) {
+ for (const key in obj) {
+ delete obj[key]
+ }
+}
-function prepareInstance (id, options, data) {}
+/**
+ * Create an instance with id, code, config and external data.
+ * @param {string} instanceId
+ * @param {string} appCode
+ * @param {object} config
+ * @param {object} data
+ * @param {object} env { info, config, services }
+ */
+export function createInstance (
+ instanceId,
+ appCode = '',
+ config = {},
+ data,
+ env = {}
+) {
+ // Virtual-DOM object.
+ const document = new renderer.Document(instanceId, config.bundleUrl)
-function createInstance (id, code, options, data, serviceObjects) {
- const document = new config.Document(id, options.bundleUrl)
- const callbacks = {}
+ // All function/callback of parameters before sent to native
+ // will be converted as an id. So `callbacks` is used to store
+ // these real functions. When a callback invoked and won't be
+ // called again, it should be removed from here automatically.
+ const callbacks = []
- let lastCallbackId = 0
- document.addCallback = func => {
- lastCallbackId++
- callbacks[lastCallbackId] = func
- return lastCallbackId
- }
- document.handleCallback = (funcId, data, ifLast) => {
- const callback = callbacks[funcId]
- if (ifLast) {
- delete callbacks[funcId]
- }
- return callback(data)
+ // The latest callback id, incremental.
+ const callbackId = 1
+
+ instances[instanceId] = {
+ instanceId, config, data,
+ document, callbacks, callbackId
}
- instanceMap[id] = document
- const globalObjects = Object.assign({
- Document: config.Document,
- Element: config.Element,
- Comment: config.Comment,
- sendTasks: config.sendTasks,
- id, options, data, document
- }, serviceObjects)
+ // Prepare native module getter and HTML5 Timer APIs.
+ const moduleGetter = genModuleGetter(instanceId)
+ const timerAPIs = getInstanceTimer(instanceId, moduleGetter)
- const globalKeys = []
- const globalValues = []
- for (const key in globalObjects) {
- globalKeys.push(key)
- globalValues.push(globalObjects[key])
+ // Prepare `weex` instance variable.
+ const weexInstanceVar = {
+ config,
+ document,
+ requireModule: moduleGetter
}
- globalKeys.push(code)
+ Object.freeze(weexInstanceVar)
- const result = new Function(...globalKeys)
- return result(...globalValues)
+ // The function which create a closure the JS Bundle will run in.
+ // It will declare some instance variables like HTML5 Timer APIs etc.
+ const instanceVars = Object.assign({
+ weex: weexInstanceVar,
+ // deprecated
+ __weex_require_module__: weexInstanceVar.requireModule // eslint-disable-line
+ }, timerAPIs)
+ callFunction(instanceVars, appCode)
--- End diff --
Work in progress: https://github.com/vuejs/vue/pull/5049
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-weex issue #126: Jsfm feature vanilla
Posted by Hanks10100 <gi...@git.apache.org>.
Github user Hanks10100 commented on the issue:
https://github.com/apache/incubator-weex/pull/126
The `document.addCallback` is no longer supported, those test cases should be rewritten someday.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-weex issue #126: Jsfm feature vanilla
Posted by Hanks10100 <gi...@git.apache.org>.
Github user Hanks10100 commented on the issue:
https://github.com/apache/incubator-weex/pull/126
That because the node.js environment doesn't have the `callNative` method. You should mock that method in tests.
1. Import `sinon`, which is already in the `devDependencies` of package.json.
```js
import sinon from 'sinon'
```
2. Spy the `callNative` API.
```js
describe('vanilla test', () => {
// In case there did has callNative in the environment
const originalCallNative = global.callNative
const callNativeSpy = sinon.spy()
before(() => {
global.callNative = callNativeSpy
})
afterEach(() => {
callNativeSpy.reset()
})
after(() => {
global.callNative = originalCallNative
})
it('...', () => {})
})
```
Moreover, you can use `callNativeSpy` to check the parameter of call native tasks.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-weex issue #126: Jsfm feature vanilla
Posted by Hanks10100 <gi...@git.apache.org>.
Github user Hanks10100 commented on the issue:
https://github.com/apache/incubator-weex/pull/126
@yong-chen04 The code style may also need to change to follow our eslint rules.
The line 181 and 200 should be:
```js
if () {
}
else {
}
```
not
```js
if () {
} else {
}
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-weex pull request #126: Jsfm feature vanilla
Posted by Hanks10100 <gi...@git.apache.org>.
Github user Hanks10100 commented on a diff in the pull request:
https://github.com/apache/incubator-weex/pull/126#discussion_r106684486
--- Diff: html5/frameworks/vanilla/index.js ---
@@ -1,107 +1,334 @@
-const config = {}
-const instanceMap = {}
+const instances = {}
+const modules = {}
+const components = {}
-function init (cfg) {
- config.Document = cfg.Document
- config.Element = cfg.Element
- config.Comment = cfg.Comment
- config.sendTasks = cfg.sendTasks
+const renderer = {
+ instances,
+ modules,
+ components
}
-function registerComponents (components) {}
+/**
+ * Prepare framework config, basically about the virtual-DOM and JS bridge.
+ * @param {object} cfg
+ */
+export function init (cfg) {
+ renderer.Document = cfg.Document
+ renderer.Element = cfg.Element
+ renderer.Comment = cfg.Comment
+ renderer.sendTasks = cfg.sendTasks
+}
-function registerModules (modules) {}
+/**
+ * Reset framework config and clear all registrations.
+ */
+export function reset () {
+ clear(instances)
+ clear(modules)
+ clear(components)
+ delete renderer.Document
+ delete renderer.Element
+ delete renderer.Comment
+ delete renderer.sendTasks
+}
-function registerMethods (apis) {}
+/**
+ * Delete all keys of an object.
+ * @param {object} obj
+ */
+function clear (obj) {
+ for (const key in obj) {
+ delete obj[key]
+ }
+}
-function prepareInstance (id, options, data) {}
+/**
+ * Create an instance with id, code, config and external data.
+ * @param {string} instanceId
+ * @param {string} appCode
+ * @param {object} config
+ * @param {object} data
+ * @param {object} env { info, config, services }
+ */
+export function createInstance (
+ instanceId,
+ appCode = '',
+ config = {},
+ data,
+ env = {}
+) {
+ // Virtual-DOM object.
+ const document = new renderer.Document(instanceId, config.bundleUrl)
-function createInstance (id, code, options, data, serviceObjects) {
- const document = new config.Document(id, options.bundleUrl)
- const callbacks = {}
+ // All function/callback of parameters before sent to native
+ // will be converted as an id. So `callbacks` is used to store
+ // these real functions. When a callback invoked and won't be
+ // called again, it should be removed from here automatically.
+ const callbacks = []
- let lastCallbackId = 0
- document.addCallback = func => {
- lastCallbackId++
- callbacks[lastCallbackId] = func
- return lastCallbackId
- }
- document.handleCallback = (funcId, data, ifLast) => {
- const callback = callbacks[funcId]
- if (ifLast) {
- delete callbacks[funcId]
- }
- return callback(data)
+ // The latest callback id, incremental.
+ const callbackId = 1
+
+ instances[instanceId] = {
+ instanceId, config, data,
+ document, callbacks, callbackId
}
- instanceMap[id] = document
- const globalObjects = Object.assign({
- Document: config.Document,
- Element: config.Element,
- Comment: config.Comment,
- sendTasks: config.sendTasks,
- id, options, data, document
- }, serviceObjects)
+ // Prepare native module getter and HTML5 Timer APIs.
+ const moduleGetter = genModuleGetter(instanceId)
+ const timerAPIs = getInstanceTimer(instanceId, moduleGetter)
- const globalKeys = []
- const globalValues = []
- for (const key in globalObjects) {
- globalKeys.push(key)
- globalValues.push(globalObjects[key])
+ // Prepare `weex` instance variable.
+ const weexInstanceVar = {
+ config,
+ document,
+ requireModule: moduleGetter
}
- globalKeys.push(code)
+ Object.freeze(weexInstanceVar)
- const result = new Function(...globalKeys)
- return result(...globalValues)
+ // The function which create a closure the JS Bundle will run in.
+ // It will declare some instance variables like HTML5 Timer APIs etc.
+ const instanceVars = Object.assign({
+ weex: weexInstanceVar,
+ // deprecated
+ __weex_require_module__: weexInstanceVar.requireModule // eslint-disable-line
--- End diff --
I think the `__weex_require_module__` should be deleted as it's already deprecated.
And you can pass `document` here, such as `document: weex.document`, then the developer can use `document` directly instead of `weex.document`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-weex issue #126: Jsfm feature vanilla
Posted by jiyinyiyong <gi...@git.apache.org>.
Github user jiyinyiyong commented on the issue:
https://github.com/apache/incubator-weex/pull/126
Any plan to merge this update?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-weex pull request #126: Jsfm feature vanilla
Posted by Hanks10100 <gi...@git.apache.org>.
Github user Hanks10100 commented on a diff in the pull request:
https://github.com/apache/incubator-weex/pull/126#discussion_r106686382
--- Diff: html5/frameworks/vanilla/index.js ---
@@ -1,107 +1,334 @@
-const config = {}
-const instanceMap = {}
+const instances = {}
+const modules = {}
+const components = {}
-function init (cfg) {
- config.Document = cfg.Document
- config.Element = cfg.Element
- config.Comment = cfg.Comment
- config.sendTasks = cfg.sendTasks
+const renderer = {
+ instances,
+ modules,
+ components
}
-function registerComponents (components) {}
+/**
+ * Prepare framework config, basically about the virtual-DOM and JS bridge.
+ * @param {object} cfg
+ */
+export function init (cfg) {
+ renderer.Document = cfg.Document
+ renderer.Element = cfg.Element
+ renderer.Comment = cfg.Comment
+ renderer.sendTasks = cfg.sendTasks
+}
-function registerModules (modules) {}
+/**
+ * Reset framework config and clear all registrations.
+ */
+export function reset () {
+ clear(instances)
+ clear(modules)
+ clear(components)
+ delete renderer.Document
+ delete renderer.Element
+ delete renderer.Comment
+ delete renderer.sendTasks
+}
-function registerMethods (apis) {}
+/**
+ * Delete all keys of an object.
+ * @param {object} obj
+ */
+function clear (obj) {
+ for (const key in obj) {
+ delete obj[key]
+ }
+}
-function prepareInstance (id, options, data) {}
+/**
+ * Create an instance with id, code, config and external data.
+ * @param {string} instanceId
+ * @param {string} appCode
+ * @param {object} config
+ * @param {object} data
+ * @param {object} env { info, config, services }
+ */
+export function createInstance (
+ instanceId,
+ appCode = '',
+ config = {},
+ data,
+ env = {}
+) {
+ // Virtual-DOM object.
+ const document = new renderer.Document(instanceId, config.bundleUrl)
-function createInstance (id, code, options, data, serviceObjects) {
- const document = new config.Document(id, options.bundleUrl)
- const callbacks = {}
+ // All function/callback of parameters before sent to native
+ // will be converted as an id. So `callbacks` is used to store
+ // these real functions. When a callback invoked and won't be
+ // called again, it should be removed from here automatically.
+ const callbacks = []
- let lastCallbackId = 0
- document.addCallback = func => {
- lastCallbackId++
- callbacks[lastCallbackId] = func
- return lastCallbackId
- }
- document.handleCallback = (funcId, data, ifLast) => {
- const callback = callbacks[funcId]
- if (ifLast) {
- delete callbacks[funcId]
- }
- return callback(data)
+ // The latest callback id, incremental.
+ const callbackId = 1
+
+ instances[instanceId] = {
+ instanceId, config, data,
+ document, callbacks, callbackId
}
- instanceMap[id] = document
- const globalObjects = Object.assign({
- Document: config.Document,
- Element: config.Element,
- Comment: config.Comment,
- sendTasks: config.sendTasks,
- id, options, data, document
- }, serviceObjects)
+ // Prepare native module getter and HTML5 Timer APIs.
+ const moduleGetter = genModuleGetter(instanceId)
+ const timerAPIs = getInstanceTimer(instanceId, moduleGetter)
- const globalKeys = []
- const globalValues = []
- for (const key in globalObjects) {
- globalKeys.push(key)
- globalValues.push(globalObjects[key])
+ // Prepare `weex` instance variable.
+ const weexInstanceVar = {
+ config,
+ document,
+ requireModule: moduleGetter
}
- globalKeys.push(code)
+ Object.freeze(weexInstanceVar)
- const result = new Function(...globalKeys)
- return result(...globalValues)
+ // The function which create a closure the JS Bundle will run in.
+ // It will declare some instance variables like HTML5 Timer APIs etc.
+ const instanceVars = Object.assign({
+ weex: weexInstanceVar,
+ // deprecated
+ __weex_require_module__: weexInstanceVar.requireModule // eslint-disable-line
+ }, timerAPIs)
+ callFunction(instanceVars, appCode)
--- End diff --
Since all the js bundle shared the same Weex runtime, I think it's better to wrap an IFFE to the `appCode` before `callFunction`.
See https://github.com/alibaba/weex/pull/1626 for more information.
```js
// wrap IFFE and use strict mode
appCode = `(function(global){"use strict";\n ${appCode} \n})(Object.create(this))`
callFunction(instanceVars, appCode)
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-weex issue #126: Jsfm feature vanilla
Posted by yong-chen04 <gi...@git.apache.org>.
Github user yong-chen04 commented on the issue:
https://github.com/apache/incubator-weex/pull/126
Since it's the only failure.. Anything else I need to do on this PR?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---