You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Proposal: Support returning value synchronously for module methods
Background
Now all module methods are asynchronous only and have no return value.
We have to switch all APIs into async mode like this:
var storage = require('@weex-module/storage');
storage.length(function(e) {
});
As discussed in #968 , it's not simple and clear enough to use and different with web-standard API, which always bring a lot of trouble to us.
I consider that module extending principle should be:
If there is a web API standard already, we should export API according to the standard definition, providing extension API according to the actual situation at the same time.
There are a lot of web APIs that need a return value, such as Geolocation, so the ability to return value synchronously should be necessary.
Introduction
We will add two js-native call functions:
1.callNativeModule
var returnValue = callNativeModule(instanceId, module, method, arguments, options)
instanceId: (string) identify of the weex instance module: (string) name of the module to be called on. method: (string) name of the method to be called. arguments:(array) an array object specifying the arguments with which method should be called. options:(object) options object used to API extending, default is {}. returnValue:(all-types) the return value returned by calling module's method.
2.callNativeComponent
callNativeComponent(instanceId, componentRef, method, arguments, options) // Not support return value.
instanceId: (string) identify of the weex instance componentRef: (string) ref of the component to be called on. method: (string) name of the method to be called. arguments:(array) an array object specifying the arguments with which method should be called. options:(object) options object used to API extending, default is {}. returnValue:(all-types) the return value returned by calling component's method.
Renderer
Renderer should implement the two APIs,dispatch them to original module/component method and export the return value to js.
module methods that returning value synchronously should be registered differently from the async ones.
JS Framework
JS's module call:
var storage = require('@weex-module/storage')
var length = storage.length()
JS Framework should dispatch them to callNativeModule call:
var returnValue = callNativeModule(instanceId, 'storage', 'length',[], {});
In a similar way, component method:
var el = this.$el('web')
el.goBack()
should be dispatched to callNativeComponent:
var returnValue = callNativeComponent(instanceId, componentRef, 'goback', [], {});
Devtool
Dev-tool should also implement the two APIs using web socket communication.
Performance
Calling callNativeModule once takes about 0.1ms on iPhone 6
Other benchmarks will come soon...
The text was updated successfully, but these errors were encountered:
Proposal: Support returning value synchronously for module methods
Background
Now all module methods are asynchronous only and have no return value.
We have to switch all APIs into async mode like this:
As discussed in #968 , it's not simple and clear enough to use and different with web-standard API, which always bring a lot of trouble to us.
I consider that module extending principle should be:
There are a lot of web APIs that need a return value, such as Geolocation, so the ability to return value synchronously should be necessary.
Introduction
We will add two js-native call functions:
1.callNativeModule
instanceId: (string) identify of the weex instance
module: (string) name of the module to be called on.
method: (string) name of the method to be called.
arguments:(array) an array object specifying the arguments with which method should be called.
options:(object) options object used to API extending, default is {}.
returnValue:(all-types) the return value returned by calling module's method.
2.callNativeComponent
instanceId: (string) identify of the weex instance
componentRef: (string) ref of the component to be called on.
method: (string) name of the method to be called.
arguments:(array) an array object specifying the arguments with which method should be called.
options:(object) options object used to API extending, default is {}.
returnValue:(all-types) the return value returned by calling component's method.
Renderer
JS Framework
JS's module call:
JS Framework should dispatch them to
callNativeModule
call:In a similar way, component method:
should be dispatched to
callNativeComponent
:Devtool
Dev-tool should also implement the two APIs using web socket communication.
Performance
callNativeModule
once takes about 0.1ms on iPhone 6The text was updated successfully, but these errors were encountered: