Skip to content

Commit a64a252

Browse files
author
Joao Moura
committed
Fixed flow config, fixed promise call
1 parent 8fbecbe commit a64a252

File tree

3 files changed

+29
-38
lines changed

3 files changed

+29
-38
lines changed

.flowconfig

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,21 @@
11
[ignore]
2-
3-
; Ignore react-native-fbads dependency of the expo sdk
2+
.*/node_modules/react-event-listener/*
3+
.*/node_modules/jss/*
4+
.*/node_modules/flow-coverage-report/*
5+
.*/node_modules/findup/*
46
.*/lib/*
57
.*/example/*
68

7-
; Ignore libraries with broken flow
8-
9-
<PROJECT_ROOT>/node_modules/.*
109
[include]
1110

1211
[libs]
12+
/flow-typed
1313

14+
[lints]
15+
all=warn
1416
[options]
15-
module.system=haste
1617
module.system.node.resolve_dirname=node_modules
17-
module.system.node.resolve_dirname=src
18-
19-
emoji=true
20-
21-
experimental.strict_type_args=true
22-
23-
munge_underscores=true
24-
25-
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
26-
27-
suppress_type=$FlowIssue
28-
suppress_type=$FlowFixMe
29-
suppress_type=$FixMe
30-
31-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
32-
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
33-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
34-
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
3518

36-
unsafe.enable_getters_and_setters=true
3719

3820
[version]
3921
^0.59.0

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-multi-lang",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "React Multilanguage Higher-Order Component",
55
"main": "lib/index.js",
66
"files": [

src/index.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ import hoistStatics from 'hoist-non-react-statics'
88

99
let language: string = 'pt'
1010

11-
let subscribes: {
12-
cb: () => mixed,
11+
type Subscription = {
12+
promise: Promise<any>,
1313
id: string
14-
}[] = []
14+
}
15+
16+
let subscribes: Subscription[] = []
17+
1518
export type Translations = {
1619
[string]: {
1720
[string]: string
@@ -22,24 +25,26 @@ export type T = (key: string, args?: {[string]: string}) => string
2225

2326
let translations: Translations = {}
2427

25-
export function subscribe (cb:() => mixed, id?: string): string {
28+
export function subscribe (promise: Promise<any>, id?: string): string {
2629
const newId = id || uuid.v1()
2730
subscribes.push({
28-
cb,
31+
promise: promise,
2932
id: newId
3033
})
3134
return newId
3235
}
3336

3437
export function unsubscribe (id: string): void {
3538
subscribes = subscribes.filter(
36-
item => item.id !== id
39+
(item: Subscription) => item.id !== id
3740
)
3841
}
3942

40-
function triggerSubscriptions (): void {
43+
function triggerSubscriptions () {
4144
subscribes.forEach(
42-
item => item.cb()
45+
(item: Subscription) => {
46+
item.promise.then()
47+
}
4348
)
4449
}
4550

@@ -70,7 +75,7 @@ export function t (key: string, args?: {[string]: string}): string {
7075
if (args) {
7176
Object.keys(args).forEach(
7277
key => {
73-
translation = translation.replace(`{${key}}`, args[key])
78+
translation = translation.replace(`{${key}}`, args ? args[key]: '')
7479
}
7580
)
7681
}
@@ -82,9 +87,13 @@ export function translate (Component: React$ComponentType<*>): React$ComponentTy
8287
id: string
8388

8489
componentDidMount () {
85-
this.id = subscribe(() => {
86-
this.forceUpdate()
87-
})
90+
this.id = subscribe(
91+
new Promise(
92+
(resolve, reject) => {
93+
this.forceUpdate()
94+
}
95+
)
96+
)
8897
}
8998

9099
componentWillUnmount () {

0 commit comments

Comments
 (0)