Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 1510053

Browse files
committed
refactor(update): use new generators & update react to latest
1 parent 10e609b commit 1510053

17 files changed

+84
-95
lines changed

package-docker.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
"ramda": "0.25.0",
5151
"randomcolor": "^0.5.3",
5252
"raven-js": "^3.26.4",
53-
"react": "16.6.0",
53+
"react": "16.8.1",
5454
"react-calendar-heatmap": "^1.6.3",
5555
"react-click-outside": "^3.0.1",
5656
"react-content-loader": "3.1.2",
57-
"react-dom": "16.6.0",
57+
"react-dom": "16.8.1",
5858
"react-intl": "2.4.0",
5959
"react-json-view": "1.19.1",
6060
"react-keydown": "1.9.7",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@
9090
"ramda": "0.25.0",
9191
"randomcolor": "^0.5.3",
9292
"raven-js": "^3.26.4",
93-
"react": "16.6.0",
93+
"react": "16.8.1",
9494
"react-calendar-heatmap": "^1.6.3",
9595
"react-click-outside": "^3.0.1",
9696
"react-content-loader": "3.1.2",
97-
"react-dom": "16.6.0",
97+
"react-dom": "16.8.1",
9898
"react-intl": "2.4.0",
9999
"react-json-view": "1.19.1",
100100
"react-keydown": "1.9.7",

utils/scripts/component_exists.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
const fs = require('fs')
88
const path = require('path')
99

10-
const appComponents = fs.readdirSync(path.join(__dirname, 'components'))
10+
const appComponents = fs.readdirSync(path.join(__dirname, '../../components'))
1111
const appPages = fs.readdirSync(path.join(__dirname, '../../pages'))
1212
const components = appComponents.concat(appPages)
1313

utils/scripts/generators/component/class.js.hbs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ import { FormattedMessage } from 'react-intl'
1515
import messages from './messages'
1616
{{/if}}
1717

18-
import { makeDebugger } from 'utils'
18+
import { makeDebugger } from '@utils'
1919

20-
/* eslint-disable no-unused-vars */
20+
/* eslint-disable-next-line */
2121
const debug = makeDebugger('c:{{ properCase name }}:index')
22-
/* eslint-enable no-unused-vars */
22+
2323

2424
class {{ properCase name }} extends React.PureComponent {
25-
componentDidMount() {}
25+
constructor(props) {
26+
super(props)
27+
}
2628

27-
componentWillUnmount() {}
29+
// componentWillUnmount() {}
2830

2931
render() {
3032
return (

utils/scripts/generators/component/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ module.exports = {
6363
const actions = [
6464
{
6565
type: 'add',
66-
path: 'components/{{properCase name}}/index.js',
66+
path: '../../../components/{{properCase name}}/index.js',
6767
templateFile: componentTemplate,
6868
abortOnFail: true,
6969
},
7070
{
7171
type: 'add',
72-
path: 'components/{{properCase name}}/tests/index.test.js',
72+
path: '../../../components/{{properCase name}}/tests/index.test.js',
7373
templateFile: './component/test.js.hbs',
7474
abortOnFail: true,
7575
},
@@ -79,7 +79,7 @@ module.exports = {
7979
if (data.wantI18n) {
8080
actions.push({
8181
type: 'add',
82-
path: 'components/{{properCase name}}/lang.js',
82+
path: '../../../components/{{properCase name}}/lang.js',
8383
templateFile: './component/lang.js.hbs',
8484
abortOnFail: true,
8585
})
@@ -88,7 +88,7 @@ module.exports = {
8888
if (data.wantStyle) {
8989
actions.push({
9090
type: 'add',
91-
path: 'components/{{properCase name}}/styles/index.js',
91+
path: '../../../components/{{properCase name}}/styles/index.js',
9292
templateFile: './component/styles.js.hbs',
9393
abortOnFail: true,
9494
})

utils/scripts/generators/component/loadable.js.hbs

Lines changed: 0 additions & 12 deletions
This file was deleted.

utils/scripts/generators/component/stateless.js.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import { FormattedMessage as I18n } from 'react-intl'
1515
import lang from './lang'
1616
{{/if}}
1717

18-
import { makeDebugger } from 'utils'
18+
import { makeDebugger } from '@utils'
1919

20-
/* eslint-disable no-unused-vars */
20+
/* eslint-disable-next-line */
2121
const debug = makeDebugger('c:{{ properCase name }}:index')
22-
/* eslint-enable no-unused-vars */
22+
2323

2424
const {{ properCase name }} = (props) => {
2525
return (
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styled from 'styled-components'
22

3-
// import Img from '../../Img'
4-
// import { theme } from 'utils'
3+
// import Img from '@Img'
4+
// import { theme } from '@utils'
55

66
export const Wrapper = styled.div``
77
export const Title = styled.div``

utils/scripts/generators/container/class.js.hbs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,30 @@
55
*/
66

77
import React from 'react'
8-
import { inject, observer } from 'mobx-react'
98
{{#if wantMessages}}
109
import { FormattedMessage } from 'react-intl'
1110
import messages from './messages'
1211
{{/if}}
1312

14-
// import { } from './styles'
15-
16-
import { makeDebugger, storePlug } from 'utils'
13+
import { connectStore, makeDebugger } from '@utils'
1714

15+
// import { } from './styles'
1816
import * as logic from './logic'
19-
/* eslint-disable no-unused-vars */
17+
18+
/* eslint-disable-next-line */
2019
const debug = makeDebugger('C:{{ properCase name }}')
21-
/* eslint-enable no-unused-vars */
2220

23-
// NOTE: add me to containers/index
21+
2422
class {{ properCase name }}Container extends React.Component {
2523
componentDidMount() {
2624
const {{preCurly ""}} {{ camelCase name}} {{afterCurly ""}} = this.props
2725
logic.init({{ camelCase name }})
2826
}
2927

28+
componentWillUnmount() {
29+
logic.uninit()
30+
}
31+
3032
render() {
3133
return (
3234
<div>
@@ -40,4 +42,4 @@ class {{ properCase name }}Container extends React.Component {
4042
}
4143
}
4244

43-
export default inject(storePlug('{{ camelCase name }}'))(observer({{ properCase name }}Container))
45+
export default connectStore({{ properCase name }}Container)

utils/scripts/generators/container/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,37 @@ module.exports = {
4444
const actions = [
4545
{
4646
type: 'add',
47-
path: 'containers/{{properCase name}}/index.js',
47+
path: '../../../containers/{{properCase name}}/index.js',
4848
templateFile: './container/class.js.hbs',
4949
abortOnFail: true,
5050
},
5151
{
5252
type: 'add',
53-
path: 'containers/{{properCase name}}/logic.js',
53+
path: '../../../containers/{{properCase name}}/logic.js',
5454
templateFile: './container/logic.js.hbs',
5555
abortOnFail: true,
5656
},
5757
{
5858
type: 'add',
59-
path: 'containers/{{properCase name}}/store.js',
59+
path: '../../../containers/{{properCase name}}/store.js',
6060
templateFile: './container/store.js.hbs',
6161
abortOnFail: true,
6262
},
6363
{
6464
type: 'add',
65-
path: 'containers/{{properCase name}}/styles/index.js',
65+
path: '../../../containers/{{properCase name}}/styles/index.js',
6666
templateFile: './container/styles.js.hbs',
6767
abortOnFail: true,
6868
},
6969
{
7070
type: 'add',
71-
path: 'containers/{{properCase name}}/tests/index.test.js',
71+
path: '../../../containers/{{properCase name}}/tests/index.test.js',
7272
templateFile: './container/test.js.hbs',
7373
abortOnFail: true,
7474
},
7575
{
7676
type: 'add',
77-
path: 'containers/{{properCase name}}/tests/store.test.js',
77+
path: '../../../containers/{{properCase name}}/tests/store.test.js',
7878
templateFile: './container/store.test.js.hbs',
7979
abortOnFail: true,
8080
},
@@ -83,7 +83,7 @@ module.exports = {
8383
if (data.wantSchema) {
8484
actions.push({
8585
type: 'add',
86-
path: 'containers/{{properCase name}}/schema.js',
86+
path: '../../../containers/{{properCase name}}/schema.js',
8787
templateFile: './container/schema.js.hbs',
8888
abortOnFail: true,
8989
})
@@ -93,7 +93,7 @@ module.exports = {
9393
if (data.wantI18n) {
9494
actions.push({
9595
type: 'add',
96-
path: 'containers/{{properCase name}}/lang.js',
96+
path: '../../../containers/{{properCase name}}/lang.js',
9797
templateFile: './container/lang.js.hbs',
9898
abortOnFail: true,
9999
})

utils/scripts/generators/container/loadable.js.hbs

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// import R from 'ramda'
22

3-
import { makeDebugger, $solver, asyncErr, ERR } from 'utils'
4-
import SR71 from 'utils/network/sr71'
3+
import { makeDebugger, $solver, asyncErr, ERR, errRescue } from '@utils'
54

5+
import SR71 from '@utils/async/sr71'
66
// import S from './schema'
77

88
const sr71$ = new SR71()
99
let sub$ = null
10+
let store = null
1011

11-
/* eslint-disable no-unused-vars */
12+
/* eslint-disable-next-line */
1213
const debug = makeDebugger('L:{{ properCase name }}')
13-
/* eslint-enable no-unused-vars */
1414

15-
let store = null
15+
export const someMethod = () => {}
1616

17-
export function someMethod() {}
17+
// const const cancleLoading = () => {}
1818

1919
// ###############################
2020
// Data & Error handlers
@@ -23,30 +23,39 @@ export function someMethod() {}
2323
const DataSolver = []
2424
const ErrSolver = [
2525
{
26-
match: asyncErr(ERR.CRAPHQL),
27-
action: ({ details }) => {
28-
debug('ERR.CRAPHQL -->', details)
26+
match: asyncErr(ERR.GRAPHQL),
27+
action: () => {
28+
// cancleLoading()
2929
},
3030
},
3131
{
3232
match: asyncErr(ERR.TIMEOUT),
3333
action: ({ details }) => {
34-
debug('ERR.TIMEOUT -->', details)
34+
// cancleLoading()
35+
errRescue({ type: ERR.TIMEOUT, details, path: '{{ properCase name }}' })
3536
},
3637
},
3738
{
3839
match: asyncErr(ERR.NETWORK),
39-
action: ({ details }) => {
40-
debug('ERR.NETWORK -->', details)
40+
action: () => {
41+
// cancleLoading()
42+
errRescue({ type: ERR.NETWORK, path: '{{ properCase name }}' })
4143
},
4244
},
4345
]
4446

45-
export function init(_store) {
46-
if (store) return false
47+
export const init = (_store) => {
4748
store = _store
4849

4950
debug(store)
50-
if (sub$) sub$.unsubscribe()
51+
if (sub$) return false
5152
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
5253
}
54+
55+
export const uninit = () => {
56+
if (!sub$) return false
57+
debug('===== do uninit')
58+
sr71$.stop()
59+
sub$.unsubscribe()
60+
sub$ = null
61+
}

utils/scripts/generators/container/store.js.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import { types as t, getParent } from 'mobx-state-tree'
77
// import R from 'ramda'
88

9-
import { markStates, makeDebugger } from 'utils'
10-
/* eslint-disable no-unused-vars */
9+
import { markStates, makeDebugger } from '@utils'
10+
/* eslint-disable-next-line */
1111
const debug = makeDebugger('S:{{ properCase name }}')
12-
/* eslint-enable no-unused-vars */
12+
1313

1414
// NOTE: add me to stores/index && stores/RootStore/index
1515
const {{ properCase name }} = t
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styled from 'styled-components'
22

3-
// import Img from 'components/Img'
4-
// import { theme } from 'utils'
3+
// import Img from '@components/Img'
4+
// import { theme } from '@utils'
55

66
export const Wrapper = styled.div``
77
export const Title = styled.div``

utils/scripts/generators/store/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ module.exports = {
3131
const actions = [
3232
{
3333
type: 'add',
34-
path: 'stores/{{properCase name}}/index.js',
34+
path: '../stores/{{properCase name}}/index.js',
3535
templateFile: './store/store.js.hbs',
3636
abortOnFail: true,
3737
},
3838
{
3939
type: 'add',
40-
path: 'stores/{{properCase name}}/test/index.test.js',
40+
path: '../stores/{{properCase name}}/test/index.test.js',
4141
templateFile: './store/store.test.js.hbs',
4242
abortOnFail: true,
4343
},

utils/scripts/generators/store/store.js.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import { types as t, getParent } from 'mobx-state-tree'
77
// import R from 'ramda'
88

9-
import { markStates, makeDebugger } from 'utils'
10-
/* eslint-disable no-unused-vars */
9+
import { markStates, makeDebugger } from '@utils'
10+
/* eslint-disable-next-line */
1111
const debug = makeDebugger('S:{{ properCase name }}')
12-
/* eslint-enable no-unused-vars */
12+
1313

1414
const {{ properCase name }} = t
1515
.model('{{ properCase name }}', {})

0 commit comments

Comments
 (0)