Skip to content

Commit 2818be8

Browse files
author
Joao Moura
committed
Removed react-native-uuid dependency
1 parent a4cd608 commit 2818be8

File tree

3 files changed

+18
-36
lines changed

3 files changed

+18
-36
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-multi-lang",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "React Multilanguage Higher-Order Component",
55
"main": "lib/index.js",
66
"files": [
@@ -42,7 +42,6 @@
4242
"flow-copy-source": "^1.2.1"
4343
},
4444
"dependencies": {
45-
"hoist-non-react-statics": "^2.3.1",
46-
"react-native-uuid": "^1.4.9"
45+
"hoist-non-react-statics": "^2.3.1"
4746
}
4847
}

src/index.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
// @flow
22

33
import * as React from 'react'
4-
import uuid from 'react-native-uuid'
54

65
// statics handler
76
import hoistStatics from 'hoist-non-react-statics'
87

98
let language: string = 'pt'
9+
let id: number = 0
1010

11-
type Subscription = {
12-
cb: () => mixed,
13-
id: string
14-
}
11+
type Subscription = (() => mixed)
1512

16-
let subscribes: Subscription[] = []
13+
let subscribes: {
14+
[key: number | string]: Subscription
15+
} = {}
1716

1817
type Translation = {
1918
[string]: string | Translation
@@ -27,27 +26,23 @@ export type T = (path: string, args?: {[string]: string}) => string
2726

2827
let translations: Translations = {}
2928

30-
export function subscribe (cb: () => mixed, id?: string): string {
31-
const newId = id || uuid.v1()
32-
subscribes.push({
33-
cb,
34-
id: newId
35-
})
29+
export function subscribe (cb: () => mixed): number {
30+
const newId = id
31+
subscribes[newId] = cb
32+
id += 1
3633
return newId
3734
}
3835

39-
export function unsubscribe (id: string): void {
40-
subscribes = subscribes.filter(
41-
(item: Subscription) => item.id !== id
42-
)
36+
export function unsubscribe (id: number): void {
37+
delete subscribes[id]
4338
}
4439

4540
function triggerSubscriptions () {
46-
subscribes.forEach(
47-
(item: Subscription) => {
41+
Object.keys(subscribes).forEach(
42+
(id: string) => {
4843
new Promise(
4944
(resolve, reject) => {
50-
item.cb()
45+
subscribes[id]()
5146
resolve()
5247
}
5348
).then()
@@ -109,7 +104,7 @@ export function t (path: string, args?: {[string]: string}): string {
109104

110105
export function translate (Component: React$ComponentType<*>): React$ComponentType<*> {
111106
class TranslatedComponet extends React.Component<{}, *> {
112-
id: string
107+
id: number
113108

114109
componentDidMount () {
115110
this.id = subscribe(() => this.forceUpdate())

yarn.lock

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,12 +2040,6 @@ randomatic@^1.1.3:
20402040
is-number "^3.0.0"
20412041
kind-of "^4.0.0"
20422042

2043-
randombytes@^2.0.3:
2044-
version "2.0.5"
2045-
resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.0.5.tgz#dc009a246b8d09a177b4b7a0ae77bc570f4b1b79"
2046-
dependencies:
2047-
safe-buffer "^5.1.0"
2048-
20492043
rc@^1.1.7:
20502044
version "1.2.2"
20512045
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.2.tgz#d8ce9cb57e8d64d9c7badd9876c7c34cbe3c7077"
@@ -2055,12 +2049,6 @@ rc@^1.1.7:
20552049
minimist "^1.2.0"
20562050
strip-json-comments "~2.0.1"
20572051

2058-
react-native-uuid@^1.4.9:
2059-
version "1.4.9"
2060-
resolved "https://registry.yarnpkg.com/react-native-uuid/-/react-native-uuid-1.4.9.tgz#a526742f8fddfe6414500655212ca8d109c40229"
2061-
dependencies:
2062-
randombytes "^2.0.3"
2063-
20642052
read-pkg-up@^2.0.0:
20652053
version "2.0.0"
20662054
resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-2.0.0.tgz#6b72a8048984e0c41e79510fd5e9fa99b3b549be"
@@ -2210,7 +2198,7 @@ rx-lite@*, rx-lite@^4.0.8:
22102198
version "4.0.8"
22112199
resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-4.0.8.tgz#0b1e11af8bc44836f04a6407e92da42467b79444"
22122200

2213-
safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
2201+
safe-buffer@^5.0.1, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
22142202
version "5.1.1"
22152203
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853"
22162204

0 commit comments

Comments
 (0)