Skip to content

Commit f319bef

Browse files
Hanks10100yyx990803
authored andcommitted
chore: update weex flow type annotations (vuejs#7322)
1 parent ff8fcd2 commit f319bef

File tree

5 files changed

+69
-25
lines changed

5 files changed

+69
-25
lines changed

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"plugin:flowtype/recommended"
99
],
1010
"globals": {
11-
"__WEEX__": true
11+
"__WEEX__": true,
12+
"WXEnvironment": true
1213
}
1314
}

flow/weex.js

+45-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,49 @@
11
// global flag to be compiled away
22
declare var __WEEX__: boolean;
33

4+
// global object in Weex
5+
declare var WXEnvironment: WeexEnvironment;
6+
47
declare type Weex = {
5-
config: Object;
8+
config: WeexConfigAPI;
69
document: WeexDocument;
710
requireModule: (name: string) => Object | void;
811
supports: (condition: string) => boolean | void;
912
isRegisteredModule: (name: string, method?: string) => boolean;
1013
isRegisteredComponent: (name: string) => boolean;
1114
};
1215

16+
declare type WeexConfigAPI = {
17+
bundleUrl: string; // === weex.document.URL
18+
bundleType: string;
19+
env: WeexEnvironment; // === WXEnvironment
20+
};
21+
22+
declare type WeexEnvironment = {
23+
platform: string; // could be "Web", "iOS", "Android"
24+
weexVersion: string; // the version of WeexSDK
25+
26+
osName: string; // could be "iOS", "Android" or others
27+
osVersion: string;
28+
appName: string; // mobile app name or browser name
29+
appVersion: string;
30+
31+
// informations of current running device
32+
deviceModel: string; // phone device model
33+
deviceWidth: number;
34+
deviceHeight: number;
35+
scale: number;
36+
37+
// only available on the web
38+
userAgent?: string;
39+
dpr?: number;
40+
rem?: number;
41+
};
42+
1343
declare interface WeexDocument {
14-
id: string | number;
44+
id: string;
1545
URL: string;
16-
taskCenter: Object;
46+
taskCenter: WeexTaskCenter;
1747

1848
open: () => void;
1949
close: () => void;
@@ -23,11 +53,19 @@ declare interface WeexDocument {
2353
destroy: () => void;
2454
};
2555

56+
declare interface WeexTaskCenter {
57+
instanceId: string;
58+
callbackManager: Object;
59+
send: (type: string, params: Object, args: Array<any>, options?: Object) => void;
60+
registerHook: (componentId: string, type: string, hook: string, fn: Function) => void;
61+
updateData: (componentId: string, data: Object | void, callback?: Function) => void;
62+
};
63+
2664
declare interface WeexElement {
2765
nodeType: number;
28-
nodeId: string | number;
66+
nodeId: string;
2967
type: string;
30-
ref: string | number;
68+
ref: string;
3169
text?: string;
3270

3371
parentNode: WeexElement | void;
@@ -47,11 +85,11 @@ declare interface WeexElement {
4785
removeEvent: (type: string) => void;
4886
fireEvent: (type: string) => void;
4987
destroy: () => void;
50-
}
88+
};
5189

5290
declare type WeexInstanceOption = {
5391
instanceId: string;
54-
config: Object;
92+
config: WeexConfigAPI;
5593
document: WeexDocument;
5694
Vue?: GlobalAPI;
5795
app?: Component;

src/core/util/env.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* @flow */
2-
declare var WXEnvironment: any;
32

43
// can we use __proto__?
54
export const hasProto = '__proto__' in {}
+21-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
/* globals document */
2-
// document is injected by weex factory wrapper
1+
/* @flow */
2+
declare var document: WeexDocument;
33

44
import TextNode from 'weex/runtime/text-node'
55

66
export const namespaceMap = {}
77

8-
export function createElement (tagName) {
8+
export function createElement (tagName: string): WeexElement {
99
return document.createElement(tagName)
1010
}
1111

12-
export function createElementNS (namespace, tagName) {
12+
export function createElementNS (namespace: string, tagName: string): WeexElement {
1313
return document.createElement(namespace + ':' + tagName)
1414
}
1515

16-
export function createTextNode (text) {
16+
export function createTextNode (text: string) {
1717
return new TextNode(text)
1818
}
1919

20-
export function createComment (text) {
20+
export function createComment (text: string) {
2121
return document.createComment(text)
2222
}
2323

24-
export function insertBefore (node, target, before) {
24+
export function insertBefore (
25+
node: WeexElement,
26+
target: WeexElement,
27+
before: WeexElement
28+
) {
2529
if (target.nodeType === 3) {
2630
if (node.type === 'text') {
2731
node.setAttr('value', target.text)
@@ -36,15 +40,15 @@ export function insertBefore (node, target, before) {
3640
node.insertBefore(target, before)
3741
}
3842

39-
export function removeChild (node, child) {
43+
export function removeChild (node: WeexElement, child: WeexElement) {
4044
if (child.nodeType === 3) {
4145
node.setAttr('value', '')
4246
return
4347
}
4448
node.removeChild(child)
4549
}
4650

47-
export function appendChild (node, child) {
51+
export function appendChild (node: WeexElement, child: WeexElement) {
4852
if (child.nodeType === 3) {
4953
if (node.type === 'text') {
5054
node.setAttr('value', child.text)
@@ -60,22 +64,24 @@ export function appendChild (node, child) {
6064
node.appendChild(child)
6165
}
6266

63-
export function parentNode (node) {
67+
export function parentNode (node: WeexElement): WeexElement | void {
6468
return node.parentNode
6569
}
6670

67-
export function nextSibling (node) {
71+
export function nextSibling (node: WeexElement): WeexElement | void {
6872
return node.nextSibling
6973
}
7074

71-
export function tagName (node) {
75+
export function tagName (node: WeexElement): string {
7276
return node.type
7377
}
7478

75-
export function setTextContent (node, text) {
76-
node.parentNode.setAttr('value', text)
79+
export function setTextContent (node: WeexElement, text: string) {
80+
if (node.parentNode) {
81+
node.parentNode.setAttr('value', text)
82+
}
7783
}
7884

79-
export function setAttribute (node, key, val) {
85+
export function setAttribute (node: WeexElement, key: string, val: any) {
8086
node.setAttr(key, val)
8187
}

src/platforms/weex/util/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* @flow */
2-
declare var document: Object;
2+
declare var document: WeexDocument;
33

44
import { warn } from 'core/util/index'
55

0 commit comments

Comments
 (0)