You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@weex.apache.org by GitBox <gi...@apache.org> on 2018/12/20 09:34:55 UTC

[GitHub] zshshr closed pull request #252: Update docs of broadcast, js-service, weex-variable, navigator

zshshr closed pull request #252: Update docs of broadcast, js-service, weex-variable, navigator
URL: https://github.com/apache/incubator-weex-site/pull/252
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/docs/docs/api/broadcast-channel.md b/docs/docs/api/broadcast-channel.md
index 7502a2ecb..de2ec9f6b 100644
--- a/docs/docs/api/broadcast-channel.md
+++ b/docs/docs/api/broadcast-channel.md
@@ -19,7 +19,7 @@ As mentioned in [JS Runtime Context](./runtime-context.html), Weex is using diff
 The constructor of `BroadcastChannel` only take one single parameter which is the channel name.
 
 ```js
-const jb = new BroadcastChannel('007')
+const bc = new BroadcastChannel('007')
 ```
 
 The type declaration of the `BroadcastChannel` is:
@@ -86,6 +86,8 @@ The page A, B and C are all create a BroadcastChannel object which is listening
 
 When Steve post the message `'Assemble!'`, Stack will receive a message event whose `data` equals the `'Assemble!'`, and then send another message back. But Hulk will not receive the message because he does not implement the `onmessage` method, so he is not a subscriber actually.
 
+> note: Stack will not receive this message which posted by himself
+
 ## Notice
 
 > **The `message` object is not deep cloned.** (This feature could be changed.)
diff --git a/docs/docs/api/js-service.md b/docs/docs/api/js-service.md
index db5a29204..315950ddd 100644
--- a/docs/docs/api/js-service.md
+++ b/docs/docs/api/js-service.md
@@ -11,9 +11,9 @@ version: 2.1
 
 <span class="weex-version">v0.9.5+</span>
 
-JS service and Weex instance are parallel in js runtime. Weex instance lifecycle will invoke JS service lifecycle. Currently provide create, refresh, destroy of lifecycle.
+JS service and Weex instance are parallel in js runtime. Weex instance's lifecycle will invoke JS service's lifecycle. Currently provide create, refresh, destroy of lifecycle.
 
-!!!Important: JS Service is very powerful. Please be careful to use.
+**!!!Important: JS Service is very powerful. Please be careful to use.**
 
 
 ## Register JS Service
@@ -34,6 +34,8 @@ String SERVICE_JS_CODE = "SERVICE_JS_CODE"
 boolean result = WXSDKEngine.registerService(SERVICE_NAME, SERVICE_JS_CODE, options)
 ```
 
+> params of `options` Could have { create, refresh, destroy } lifecycle methods. In create method it should  return an object of what variables or classes would be injected into the `Weex` instance.
+
 ### Web
 ```html
 <script src="SERVICE_JS_CODE_URL"></script>
diff --git a/docs/docs/api/weex-variable.md b/docs/docs/api/weex-variable.md
index f61db9682..d85d4813a 100644
--- a/docs/docs/api/weex-variable.md
+++ b/docs/docs/api/weex-variable.md
@@ -8,7 +8,7 @@ version: 2.1
 
 <!-- toc -->
 
-Each page of Weex contains a `weex` variable in the js runtime context. It can be assessed directly just like a global object, but it's *readonly* and separated from different pages.
+Every Weex page contains a `weex` variable in its js runtime context. It can be assessed directly just like a global object, but it is *readonly* and separated from different pages.
 
 > NOTE: **The `weex` variable only exposed in the Vue framework. It's not available in Rax framework yet.**
 
@@ -25,7 +25,7 @@ declare type Weex = {
 }
 ```
 
-## `weex.config`
+## `config`
 
 The `weex.config` contains all the environment information of current page.
 
@@ -65,7 +65,7 @@ weex.config.env === WXEnvironment
 
 [This example](http://dotwe.org/vue/ea2cff9039f3b0e406f8f7da10e874af) prints all properties in the Weex environment object.
 
-## `weex.document`
+## `document`
 
 The `weex.document` is the document object of current page, it can be used to create or manipulate the *Elements* in *DOM tree*. It's part of *Weex DOM API* specification which is NOT the same with the `document` object in the [W3C DOM API](https://www.w3.org/DOM/).
 
@@ -73,7 +73,7 @@ However, it's not a good practice to manipulate DOM directly when using modern f
 
 This API is mainly used inside of the Vue and Rax framework to convert the virtual-dom into render directives and send them to native render engines of Weex. Not recommended for using it when developing pages.
 
-## `weex.requireModule`
+## `requireModule`
 
 For those features which does not rely on the UI, Weex wraps them into **modules**. It is a way to access native capabilities in javascript. Except for the [built-in modules](./modules/), it's quite easy to integrate the existing native modules to Weex platform. After that, you can use `weex.requireModule` to require both customized and built-in modules.
 
@@ -107,7 +107,7 @@ You can require a native module and use its APIs just like normal javascript fun
 </script>
 ```
 
-## `weex.supports`
+## `supports`
 
 > This API only available in <span class="api-version">v0.15+</span>.
 
@@ -161,7 +161,7 @@ weex.supports('@stream/fetch') // null
 weex.supports('getComponentRect') // null
 ```
 
-## `weex.isRegisteredModule`
+## `isRegisteredModule`
 
 Detect whether the specific module or method is registered.
 
@@ -178,7 +178,7 @@ weex.isRegisteredModule('whatever', '- unknown -') // false
 weex.isRegisteredModule('div') // false, not support components
 ```
 
-## `weex.isRegisteredComponent`
+## `isRegisteredComponent`
 
 Detect whether the specific component is registered.
 
diff --git a/docs/docs/modules/navigator.md b/docs/docs/modules/navigator.md
index c78c528e7..6acff113c 100644
--- a/docs/docs/modules/navigator.md
+++ b/docs/docs/modules/navigator.md
@@ -20,11 +20,11 @@ Push a weex page onto the navigator stack, you can specify whether apply animati
 
 **Arguments**
 
-* options(object): some options.
-  * url(string): The URL of the weex page to push.
-  * animated(string): true, if the weex page is push through animation, otherwise, false. Default value is true.
+* `options`(object): some options.
+  * `url`(string): The URL of the weex page to push.
+  * `animated`(string): true, if the weex page is push through animation, otherwise, false. Default value is true.
 
-* callback(object): the callback function to be called after executing this action.
+* `callback`(object): the callback function to be called after executing this action.
 
 **Example**
 
@@ -46,9 +46,9 @@ pop a weex page onto the navigator stack, you can specify whether apply animatio
 
 **Arguments**
 
-* options(object): some options.
-  * animated(string): true if the weex page is pop through animation; otherwise, false. Default value is true.
-* callback(object): the callback function after executing this action.
+* `options`(object): some options.
+  * `animated`(string): true if the weex page is pop through animation; otherwise, false. Default value is true.
+* `callback`(object): the callback function after executing this action.
 
 **Example**
 
diff --git a/docs/zh/docs/api/broadcast-channel.md b/docs/zh/docs/api/broadcast-channel.md
index de7edd6a6..3b1ec4d7a 100644
--- a/docs/zh/docs/api/broadcast-channel.md
+++ b/docs/zh/docs/api/broadcast-channel.md
@@ -8,21 +8,21 @@ version: 2.1
 
 <!-- toc -->
 
-> The `BroadcastChannel` is available since <span class="api-version">v0.9+</span>.
+> `BroadcastChannel` 接口在 <span class="api-version">v0.9+</span> 及以上的版本中可用。
 
-As mentioned in [JS Runtime Context](./runtime-context.html), Weex is using different context for each page, even global variables are isolated, but `BroadcastChannel` is a way to achieve cross-page communication.
+在 [JS 执行环境](./runtime-context.html)中提到过,不同的 Weex 页面使用的是不同的执行环境,即使全局变量也是互相隔离的,然而使用 `BroadcastChannel` 是可以实现跨页面通信的。
 
 ## API
 
-> *BroadcastChannel* is part of [W3C specifications](https://html.spec.whatwg.org/multipage/comms.html#broadcasting-to-other-browsing-contexts), as well as the [MessageEvent](https://html.spec.whatwg.org/multipage/comms.html#messageevent).
+> *BroadcastChannel* 是 [W3C 规范](https://html.spec.whatwg.org/multipage/comms.html#broadcasting-to-other-browsing-contexts)中的一部分,其中依赖的 [MessageEvent](https://html.spec.whatwg.org/multipage/comms.html#messageevent) 对象也是。
 
-The constructor of `BroadcastChannel` only take one single parameter which is the channel name.
+`BroadcastChannel` 的构造函数只接受一个参数,那就是“频道名称”(channel name)。
 
 ```js
-const jb = new BroadcastChannel('007')
+const bc = new BroadcastChannel('007')
 ```
 
-The type declaration of the `BroadcastChannel` is:
+`BroadcastChannel` 接口的定义如下:
 
 ```typescript
 declare interface BroadcastChannel = {
@@ -33,12 +33,12 @@ declare interface BroadcastChannel = {
 }
 ```
 
-+ `name`: The channel name, it's the indicator when broadcast messages.
-+ `postMessage`: Sends the given message to other BroadcastChannel objects set up for this channel.
-+ `onmessage`: The event handler. An event will be triggered when the instance received a message.
-+ `close`: Closes the BroadcastChannel object, opening it up to garbage collection.
++ `name`: 监听的频道名称,用来区分不同的频道(跨频道不可通信)。
++ `postMessage`: 用于在当前频道中广播消息。
++ `onmessage`: 消息事件的处理函数。在频道中接收到广播消息之后,会给所有订阅者派发消息事件。
++ `close`: 关闭当前频道。
 
-The type declaration of the `MessageEvent` is:
+消息对象(`MessageEvent`)的类型定义如下:
 
 ```typescript
 declare interface MessageEvent = {
@@ -47,67 +47,69 @@ declare interface MessageEvent = {
 }
 ```
 
-## Communication Procedure
+## 通信过程
 
 ![BroadcastChannel](../images/BroadcastChannel.png)
 
-Just like using radio, each client joins a specific channel by creating a `BroadcastChannel` object with the same channel name. Then implement the `onmessage` event handler to listen on the underlying channel. Call the `postMessage()` method on the BroadcastChannel object will broadcast a message to every subscriber of the channel.
+就像使用无线电一样,每个页面通过创建一个具有相同频道名称的 BroadcastChannel 对象来加入特定频道。 然后实现 `onmessage` 接口来监听消息事件。通过调用 BroadcastChannel 对象上的 `postMessage()` 方法可以在频道中广播一条消息给所有订阅者。
 
-Indeed, it's a full-duplex (bi-directional) communication between all subscriber of the particular channel, each of them is able to receive any message that has been posted to it. Even the sender of the message can receive the message event itself. Communications between different channels will not affect each other.
+事实上,这是在特定频道的所有用户之间的全双工(双向)通信,每个订阅者都可以在频道中彼此收发任何消息,即使消息的发送者也能收到自己发出的消息事件。不同频道之间的通信过程是不会互相影响的。
 
-To leave a channel, it is required to call the `close()` method on the BroadcastChannel object. This method only closed itself, and does not affect other subscribers. When a Weex page is destroyed, all subscribers in it will be closed at `destroyInstance`. If all subscribers of a channel are closed, the underlying channel would be destroyed and allows garbage collection to happen.
+调用 BroadcastChannel 对象的 `close()` 方法可以离开一个频道,这个方法只关闭自己,并不影响其他订阅者。当某个 Weex 页面被销毁时,其中的所有订阅者将在 `destroyInstance` 中强制关闭。如果某个频道的所有用户都关闭了,这个频道对象将会被销毁,所占内存页能被回收。
 
-## Usage Example
+## 使用范例
 
-In page A:
+在页面 A 中:
 
 ```js
 const Steve = new BroadcastChannel('Avengers')
 Steve.postMessage('Assemble!')
 ```
 
-In page B:
+在页面 B 中:
 
 ```js
 const Hulk = new BroadcastChannel('Avengers')
 ```
 
-In page C:
+在页面 C 中:
 
 ```js
-const Stack = new BroadcastChannel('Avengers')
-Stack.onmessage = function (event) {
+const Stark = new BroadcastChannel('Avengers')
+Stark.onmessage = function (event) {
   console.log(event.data) // Assemble!
-  Stack.postMessage('I am Tony and I am leaving now.')
+  Stark.postMessage('I am Tony and I am leaving now.')
 }
 ```
 
-The page A, B and C are all create a BroadcastChannel object which is listening on the `'Avengers'` channel. They can use it to communicate with each other.
+页面 A 、B 、C 都创建一个监听了 `'Avengers'` 频道的 BroadcastChannel 对象,它们可以用这个对象实现互相通信。
 
-When Steve post the message `'Assemble!'`, Stack will receive a message event whose `data` equals the `'Assemble!'`, and then send another message back. But Hulk will not receive the message because he does not implement the `onmessage` method, so he is not a subscriber actually.
+当 Steve 发布了 `'Assemble!'` 消息时,Stark 将收到一个消息事件,其 `data` 字段等于 `'Assemble!'`,然后也向频道中回复一条消息。但是 Hulk 并不会收到这些消息,因为他没有实现`onmessage` 方法,相当于没有接收频道中的消息,所以他实际上不是一个订阅者。
 
-## Notice
+> 注释: Hulk 不会收到他自己发送的消息
 
-> **The `message` object is not deep cloned.** (This feature could be changed.)
+## 注意事项
 
-In page A:
+> **消息事件中的对象并没有深度复制。**(这个特性可能会修改)
+
+在页面 A 中:
 
 ```js
 const a = new BroadcastChannel('app')
 const list = ['A', 'B']
-a.postMessage(list)
+a.postMessage({ list })
 ```
 
-In page B:
+在页面 B 中:
 
 ```js
 const b = new BroadcastChannel('app')
 b.onmessage = function (event) {
-  // the event.data is a reference of list in page A
-  event.data.push('C')
+  // the `event.data.list` is a reference of `list` in page A
+  event.data.list.push('C')
 }
 ```
 
-In this case, the `event.data` in page B is a reference of `list` in page A. When pushing a new item `'C'`, it will also affect the `list` object in page A.
+在这个例子中,页面 B 中的 `event.data.list` 实际上是页面 A 中 `list` 对象的引用。在页面 B 中给列表添加一项 `'C'`,也将影响到页面 A 中的 `list` 对象。
 
-Compared to the deep clone, this behavior improves efficiency and reduces memory cost. However, developers are not recommended caching or modifying the `event` object after received it.
+相比于深度复制,这个行为可以减少页面中的内存消耗。开发者在使用时不应该存储或修改 `event` 对象。
diff --git a/docs/zh/docs/api/js-service.md b/docs/zh/docs/api/js-service.md
index e69de29bb..56a8ea72e 100644
--- a/docs/zh/docs/api/js-service.md
+++ b/docs/zh/docs/api/js-service.md
@@ -0,0 +1,119 @@
+---
+title: JS Service
+type: references
+group: API
+order: 2.6
+version: 2.1
+---
+
+
+# JS Service
+
+<span class="weex-version">v0.9.5+</span>
+
+JS service 和 Weex 实例在 JS runtime 中并行运行。Weex 实例的生命周期可调用 JS service 生命周期。目前提供创建、刷新、销毁生命周期。
+
+**重要提醒: JS Service 非常强大但也很危险,请小心使用!**
+
+
+## 注册 JS Service
+
+### iOS
+
+```objective-c
+[WXSDKEngine registerService:@"SERVICE_NAME" withScript: @"SERVICE_JS_CODE" withOptions: @{}];
+// or
+[WXSDKEngine registerService:@"SERVICE_NAME" serviceScriptUrl: @"SERVICE_JS_URL" withOptions: @{}];
+```
+
+### Android
+
+```java
+HashMap<String, String> options = new HashMap<>()
+options.put("k1", "v1")
+String SERVICE_NAME = "SERVICE_NAME"
+String SERVICE_JS_CODE = "SERVICE_JS_CODE"
+boolean result = WXSDKEngine.registerService(SERVICE_NAME, SERVICE_JS_CODE, options)
+```
+> params of `options` Could have { create, refresh, destroy } lifecycle methods. In create method it should  return an object of what variables or classes would be injected into the `Weex` instance.
+
+### Web
+```html
+<script src="SERVICE_JS_CODE_URL"></script>
+```
+
+
+
+## 编写一个 JS service
+
+```javascript
+service.register(SERVICE_NAME /* same string with native */, {
+  /**
+    * JS Service lifecycle. JS Service `create` will before then each instance lifecycle `create`. The return param `instance` is Weex protected param. This object will return to instance global. Other params will in the `services` at instance.
+    *
+    * @param  {String} id  instance id
+    * @param  {Object} env device environment
+    * @return {Object}
+    */
+  create: function(id, env, config) {
+    return {
+      instance: {
+        InstanceService: function(weex) {
+          var modal = weex.requireModule('modal')
+          return {
+            toast: function(title) {
+              modal.toast({ message: title })
+            }
+          }
+        }
+      },
+      NormalService: function(weex) {
+        var modal = weex.requireModule('modal')
+        return {
+          toast: function(title) {
+            modal.toast({ message: title })
+          }
+        }
+      }
+    }
+  },
+
+  /**
+    * JS Service lifecycle. JS Service `refresh` will before then each instance lifecycle `refresh`. If you want to reset variable or something on instance refresh.
+    *
+    * @param  {String} id  instance id
+    * @param  {Object} env device environment
+    */
+  refresh: function(id, env, config){
+
+  },
+
+  /**
+    * JS Service lifecycle. JS Service `destroy` will before then each instance lifecycle `destroy`. You can deleted variable here. If you doesn't detete variable define in JS Service. The variable will always in the js runtime. It's would be memory leak risk.
+    *
+    * @param  {String} id  instance id
+    * @param  {Object} env device environment
+    * @return {Object}
+    */
+  destroy: function(id, env) {
+
+  }
+})
+```
+
+## Using JS Service (vuejs)
+
+```html
+<script>
+var _InstanceService = new InstanceService(weex)
+var _NormalService = new service.NormalService(weex)
+
+module.exports = {
+  created: fucntion() {
+    // called modal module to toast something
+    _InstanceService.toast('Instance JS Service')
+    _NormalService.toast('Normal JS Service')
+  }
+}
+</script>
+```
diff --git a/docs/zh/docs/api/weex-variable.md b/docs/zh/docs/api/weex-variable.md
index e69de29bb..37c8c61ea 100644
--- a/docs/zh/docs/api/weex-variable.md
+++ b/docs/zh/docs/api/weex-variable.md
@@ -0,0 +1,195 @@
+---
+title: Weex 实例变量
+type: references
+group: API
+order: 2.5
+version: 2.1
+---
+
+<!-- toc -->
+
+每个 Weex 页面的 JS 上下文中都有一个相互独立的 `weex` 变量,它可以像全局变量一样使用,不过它在不同页面中是隔离而且*只读*的。
+
+> **注意: `weex` 实例变量只在 Vue 框架中暴露了,目前还不支持在 Rax 框架中使用。**
+
+## 属性和方法
+
+Weex 实例变量的类型定义如下:
+
+```typescript
+declare type Weex = {
+  config: WeexConfigAPI;
+  document: WeexDocument;
+  requireModule: (name: string) => Object | void;
+  supports: (condition: string) => boolean | void;
+}
+```
+
+## `config`
+
+该变量包含了当前 Weex 页面的所有环境信息。
+
+```typescript
+declare type WeexConfigAPI = {
+  bundleUrl: string;
+  bundleType?: string;
+  env: WeexEnvironment;
+}
+```
+
++ `bundleUrl`: 当前页面 js bundle 的 URL 地址。
++ `bundleType`: <span class="api-version">v0.17+</span> 页面 js bundle 的类型,它表示的是当前页面是用那种框架开发的,可以是 `"Vue"` 或者 `"Rax"`。
++ `env`: Weex 环境变量。
+
+### Weex 环境变量
+
+有时候为了兼容性或者为了增强某个端上的能力,需要编写平台特异的代码。 Weex 提供了 `weex.config.env` 和全局的 `WXEnvironment` 变量(它们是等价的)来获取当前执行环境的信息。
+
+```js
+weex.config.env === WXEnvironment
+```
+
+**Weex 环境变量中的字段**:
+
+| 字段名          | 类型    | 描述 |
+| -------------- | ------ | ----------- |
+| `platform`     | String | Current running platform, could be "Android", "iOS" or "Web". |
+| `weexVersion`  | String | The version of Weex SDK. |
+| `appName`      | String | Mobile app name or browser name. |
+| `appVersion`   | String | The version of current app. |
+| `osName`       | String | The OS name, could be "Android" or "iOS". |
+| `osVersion`    | String | The version of current OS. |
+| `deviceModel`  | String | Mobile phone device model. (native only) |
+| `deviceWidth`  | Number | Screen resolution width. |
+| `deviceHeight` | Number | Screen resolution height. |
+
+[这个例子](http://dotwe.org/vue/ea2cff9039f3b0e406f8f7da10e874af) 打印出了 Weex 环境对象中的所有值。
+
+## `document`
+
+`weex.document` 是当前页面的文档模型对象,可以用来创建和操作 DOM 树中元素。它是 Weex DOM API 规范的一部分,但是它和 [W3C 的 DOM 规范](https://www.w3.org/DOM/)中的 `document` 对象是不同的。
+
+而且,在使用了现代化的前端框架(如 Vue 和 Rax)的情况下,直接操作 DOM 并不是最佳实践。更何况**在 Weex 平台里并不一定有真实的 DOM**,在 Android 和 iOS 端上都是模拟出来的。
+
+这个接口主要是用在 Vue 和 Rax 框架内部,用于将 virtual-dom 转换成渲染执行,并且发送给 Weex 客户端的渲染引擎。不建议在开发页面时使用。
+
+## `requireModule`
+
+对于那些不依赖 UI 交互的原生功能,Weex 将其封装成**模块**,这是一种通过 javascript 调用原生能力的方法。除了[内置模块](./modules/)以外,将已有的原生模块移植到 Weex 平台也很方便。你可以使用 `weex.requireModule` 接口引用自定义的或者内置的模块。
+
+```typescript
+weex.requireModule(name: string): Object | void;
+```
+
+**参数:**
+
++ 大小写敏感的模块名。
+
+**返回值:**
+
++ 如果模块已经注册了,返回一个 `Proxy` 对象(如果环境不支持 `Proxy` 则返回一个普通对象),可以使用这个对象调用客户端注册的方法。
++ 如果模块未注册,返回 `undefined`。
+
+### 使用原生模块
+
+你可以像使用不同 javascript 函数一样使用原生注册的接口。这里是一个简单的[使用 modal 模块的例子](http://dotwe.org/vue/cd7e97f7da08d6d4ca627fc127ab8828):
+
+```html
+<template>
+  <div><text>Toast</text></div>
+</template>
+<script>
+  const modal = weex.requireModule('modal')
+  modal.toast({
+    message: 'I am a toast.',
+    duration: 3
+  })
+</script>
+```
+
+## `supports`
+
+> 这个接口只在 <span class="api-version">v0.15+</span> 或以上的版本可用。
+
+你应该了解 Weex 的组件和模块都是可以注册和配置的,这样导致了在不同环境中组件和模块的支持情况不一样。你可以使用 `weex.supports` 接口在运行期检测某个功能在当前环境中是否可用。
+
+```typescript
+weex.supports(condition: string): boolean | void;
+```
+
+**参数:**
+
++ 特定格式的字符串:`@{type}/{name}`。
+
+`type` 必须是 `"component"` 和 `"module"` 之一。`name` 可以是标签名、模块名,也可以指定模块中的某个方法名(和模块名用 `.` 隔开)。
+
+**返回值:**
+
++ 支持该特性,则返回 `true`。
++ 不支持该特性,则返回 `false`。
++ 参数格式错误或无法确定是否支持,则返回 `null`。
+
+### 使用范例
+
+检测某个组件是否可用:
+
+```js
+weex.supports('@component/slider') // true
+weex.supports('@component/my-tab') // false
+```
+
+检测某个模块是否可用:
+
+```js
+weex.supports('@module/stream')  // true
+weex.supports('@module/abcdef')  // false
+```
+
+检测某个模块是否包含某个方法:
+
+```js
+weex.supports('@module/dom.getComponentRect') // true
+weex.supports('@module/navigator.jumpToPage') // false
+```
+
+无效的输入:
+
+```js
+weex.supports('div') // null
+weex.supports('module/*') // null
+weex.supports('@stream/fetch') // null
+weex.supports('getComponentRect') // null
+```
+
+## `isRegisteredModule`
+
+检测某个特定的模块或者接口是否可用。
+
+```typescript
+weex.isRegisteredModule(moduleName: string, methodName: string): boolean
+```
+
+这个接口只能用于检测特定模块和方法的兼容性,不支持检测组件。
+
+```js
+weex.isRegisteredModule('stream') // true
+weex.isRegisteredModule('stream', 'fetch') // true
+weex.isRegisteredModule('whatever', '- unknown -') // false
+weex.isRegisteredModule('div') // false, not support components
+```
+
+## `isRegisteredComponent`
+
+检测某个特定的组件是否可用。
+
+```typescript
+weex.isRegisteredComponent(componentName: string): boolean
+```
+
+这个接口只能用于检测组件的兼容性,不支持检测模块。
+
+```js
+weex.isRegisteredComponent('div') // true
+weex.isRegisteredComponent('- unknown -') // false
+weex.isRegisteredComponent('navigator') // false, not support modules
+```


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services