You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by so...@apache.org on 2017/06/28 08:46:02 UTC
[11/37] incubator-weex git commit: - [html5] remove some useless code
in websocket module
- [html5] remove some useless code in websocket module
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/dfc5d31b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/dfc5d31b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/dfc5d31b
Branch: refs/heads/0.15-dev
Commit: dfc5d31b2efd44729dfe1ba3a6b22598c800f5ad
Parents: 5d31202
Author: erha19 <fa...@gmail.com>
Authored: Fri Jun 23 16:22:50 2017 +0800
Committer: erha19 <fa...@gmail.com>
Committed: Fri Jun 23 16:22:50 2017 +0800
----------------------------------------------------------------------
html5/render/vue/modules/websocket/websocket.js | 38 +++++++++-----------
1 file changed, 17 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/dfc5d31b/html5/render/vue/modules/websocket/websocket.js
----------------------------------------------------------------------
diff --git a/html5/render/vue/modules/websocket/websocket.js b/html5/render/vue/modules/websocket/websocket.js
index f52aa12..b430789 100644
--- a/html5/render/vue/modules/websocket/websocket.js
+++ b/html5/render/vue/modules/websocket/websocket.js
@@ -16,48 +16,44 @@
* specific language governing permissions and limitations
* under the License.
*/
-
/**
* websocket module
*/
-// let instance = null
-
-export default (function () {
- let instance = null
+export default (function() {
const registerListeners = ['onopen', 'onmessage', 'onerror', 'onclose']
const ws = {
- WebSocket: function (url, protocol) {
+ INSTANCE: null,
+ WebSocket: function(url, protocol) {
if (!url) {
return
}
if (!protocol) {
- instance = new WebSocket(url)
+ ws.INSTANCE = new WebSocket(url)
+ } else {
+ ws.INSTANCE = new WebSocket(url, protocol)
}
- else {
- instance = new WebSocket(url, protocol)
- }
- return instance
+ return ws.INSTANCE
},
- send: function (messages) {
- instance && instance.send(messages)
+ send: function(messages) {
+ ws.INSTANCE && ws.INSTANCE.send(messages)
},
- close: function () {
- instance && instance.close()
+ close: function() {
+ ws.INSTANCE && ws.INSTANCE.close()
}
}
for (const i in registerListeners) {
if (registerListeners.hasOwnProperty(i)) {
Object.defineProperty(ws, registerListeners[i], {
- get: function () {
- return instance && instance[registerListeners[i]]
+ get: function() {
+ return ws.INSTANCE && ws.INSTANCE[registerListeners[i]]
},
- set: function (fn) {
- if (instance) {
- instance[registerListeners[i]] = fn
+ set: function(fn) {
+ if (ws.INSTANCE) {
+ ws.INSTANCE[registerListeners[i]] = fn
}
}
})
}
}
return ws
-})()
+})()
\ No newline at end of file