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

Commit 71dc02b

Browse files
committed
[wip] state tree viewer
1 parent 85f512e commit 71dc02b

File tree

10 files changed

+122
-13
lines changed

10 files changed

+122
-13
lines changed

components/StateTree/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
*
3+
* StateTree
4+
*
5+
*/
6+
7+
import React from 'react'
8+
import ReactJson from 'react-json-view'
9+
10+
/* import PropTypes from 'prop-types' */
11+
12+
import { makeDebugger } from '../../utils/functions'
13+
/* eslint-disable no-unused-vars */
14+
const debug = makeDebugger('c:StateTree:index')
15+
/* eslint-enable no-unused-vars */
16+
17+
const StateTree = ({ json }) => {
18+
return (
19+
<div>
20+
<ReactJson src={json} collapsed={1} />
21+
</div>
22+
)
23+
}
24+
25+
StateTree.propTypes = {
26+
// https://www.npmjs.com/package/prop-types
27+
}
28+
29+
StateTree.defaultProps = {}
30+
31+
export default StateTree
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// import React from 'react'
2+
// import { shallow } from 'enzyme'
3+
4+
// import StateTree from '../index'
5+
6+
describe('<StateTree />', () => {
7+
it('Expect to have unit tests specified', () => {
8+
expect(true).toEqual(false)
9+
})
10+
})

containers/Preview/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
import React from 'react'
88
import { inject, observer } from 'mobx-react'
9+
import dynamic from 'next/dynamic'
910

1011
// import Link from 'next/link'
1112

1213
import { makeDebugger, storeSelector } from '../../utils/functions'
1314
import * as logic from './logic'
1415

1516
import ThemeSelector from '../../components/ThemeSelector'
17+
/* import StateTree from '../../components/StateTree' */
1618

1719
import {
1820
TheTitle,
@@ -26,6 +28,10 @@ import {
2628
CloserInner,
2729
} from './styles'
2830

31+
const StateTreeWithNoSSR = dynamic(import('../../components/StateTree'), {
32+
ssr: false,
33+
})
34+
2935
const debug = makeDebugger('C:Preview')
3036

3137
const CloseBtn = ({ type }) => (
@@ -42,6 +48,7 @@ const AccountViewer = ({ themeKeys, curTheme }) => {
4248
<TheTitle>
4349
<span>主题</span>
4450
</TheTitle>
51+
4552
<ThemeSelector
4653
themeKeys={themeKeys}
4754
curTheme={curTheme}
@@ -60,13 +67,16 @@ class PreviewContainer extends React.Component {
6067
render() {
6168
const { visible, type, themeKeys, curTheme } = this.props.preview
6269

70+
/* debug('this.props.preview: ', this.props.preview.root.toJSON()) */
71+
6372
return (
6473
<div>
6574
<PreviewOverlay visible={visible} onClick={logic.closePreview} />
6675
<PreviewWrapper visible={visible} type={type}>
6776
<CloseBtn type={type} />
6877
<PreviewContent>
6978
<PreviewHeader>Preview header</PreviewHeader>
79+
<StateTreeWithNoSSR json={this.props.preview.root.toJSON()} />
7080
<PreviewBody>
7181
<h2>Preview body</h2>
7282
{type === 'account' ? (

docs/ideas.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656

5757
## TODO
5858

59+
- [ ] add [MSTViewer](https://github.com/mac-s-g/react-json-view)
5960
- [ ] update to prism [latestest](https://github.com/PrismJS/prism/releases)
6061
- [ ] use styled-component extend to refator
6162
- [ ] use header section footer main ... html tags

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
"react-dom": "16.0.0",
116116
"react-icons": "^2.2.5",
117117
"react-intl": "2.4.0",
118+
"react-json-view": "^1.14.0",
118119
"react-keydown": "^1.9.4",
119120
"react-masonry-component": "^6.0.1",
120121
"react-svg": "^2.1.22",

pages/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ global.Intl = require('intl')
1919

2020
export default class Index extends React.Component {
2121
static getInitialProps({ req }) {
22-
const isServer = !!req
22+
/* const isServer = !!req */
2323
/* eslint-disable no-underscore-dangle */
2424
/* eslint-disable no-undef */
2525
const { locale, messages } = req || window.__NEXT_DATA__.props
2626
const langSetup = {}
2727
langSetup[locale] = messages
28-
const store = initRootStore(isServer, langSetup)
28+
const store = initRootStore(langSetup)
2929
/* eslint-enable no-undef */
3030

31-
return { isServer, version: store.version, messages, locale, langSetup }
31+
return { version: store.version, messages, locale, langSetup }
3232
}
3333

3434
constructor(props) {
3535
super(props)
36-
this.store = initRootStore(props.isServer, props.langSetup)
36+
this.store = initRootStore(props.langSetup)
3737
}
3838

3939
render() {

stores/PreviewStore/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import { types as t, getParent } from 'mobx-state-tree'
1212
const PreviewStore = t
1313
.model('PreviewStore', {
1414
visible: t.optional(t.boolean, false),
15-
type: t.optional(t.enumeration('visibleType', ['post', 'account']), 'post'),
15+
type: t.optional(
16+
t.enumeration('previewType', ['post', 'account', 'mst-state']),
17+
'post'
18+
),
1619
// header:
1720
// body:
1821
})

stores/RootStore/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const debug = makeDebugger('S:rootStore')
3131

3232
const rootStore = t
3333
.model({
34+
version: t.optional(t.string, 'old'),
3435
// domain modal
3536
route: t.optional(RouteStore, {}),
3637
communities: t.optional(CommunitiesStore, CommunitiesDefaults),
@@ -71,9 +72,6 @@ const rootStore = t
7172
get SR71$() {
7273
return getEnv(self).SR71$
7374
},
74-
get version() {
75-
return '0.0.1'
76-
},
7775
get locale() {
7876
return self.appLocale
7977
},

stores/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ import SR71$ from '../utils/SR71'
1111

1212
let rootStore = null
1313

14-
const createRootStore = (isServer, langSetup) => {
15-
return RootStore.create({ appLangs: langSetup }, { SR71$ })
14+
const createRootStore = langSetup => {
15+
return RootStore.create(
16+
{ version: 'fake from the server', appLangs: langSetup },
17+
{ SR71$ }
18+
)
1619
}
1720

18-
function initRootStore(isServer = false, langSetup) {
21+
function initRootStore(langSetup) {
1922
if (rootStore === null) {
20-
rootStore = createRootStore(isServer, langSetup)
23+
rootStore = createRootStore(langSetup)
2124
}
2225

2326
/*

yarn.lock

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,10 @@ balanced-match@^1.0.0:
13081308
version "1.0.0"
13091309
resolved "http://r.cnpmjs.org/balanced-match/download/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
13101310

1311+
base16@^1.0.0:
1312+
version "1.0.0"
1313+
resolved "https://registry.npmjs.org/base16/-/base16-1.0.0.tgz#e297f60d7ec1014a7a971a39ebc8a98c0b681e70"
1314+
13111315
base64-js@^1.0.2:
13121316
version "1.2.1"
13131317
resolved "http://r.cnpmjs.org/base64-js/download/base64-js-1.2.1.tgz#a91947da1f4a516ea38e5b4ec0ec3773675e0886"
@@ -3097,7 +3101,13 @@ fb-watchman@^2.0.0:
30973101
dependencies:
30983102
bser "^2.0.0"
30993103

3100-
fbjs@^0.8.15, fbjs@^0.8.16:
3104+
fbemitter@^2.0.0:
3105+
version "2.1.1"
3106+
resolved "https://registry.npmjs.org/fbemitter/-/fbemitter-2.1.1.tgz#523e14fdaf5248805bb02f62efc33be703f51865"
3107+
dependencies:
3108+
fbjs "^0.8.4"
3109+
3110+
fbjs@^0.8.0, fbjs@^0.8.15, fbjs@^0.8.16, fbjs@^0.8.4:
31013111
version "0.8.16"
31023112
resolved "http://r.cnpmjs.org/fbjs/download/fbjs-0.8.16.tgz#5e67432f550dc41b572bf55847b8aca64e5337db"
31033113
dependencies:
@@ -3244,6 +3254,13 @@ flat-cache@^1.2.1:
32443254
graceful-fs "^4.1.2"
32453255
write "^0.2.1"
32463256

3257+
flux@^3.1.3:
3258+
version "3.1.3"
3259+
resolved "https://registry.npmjs.org/flux/-/flux-3.1.3.tgz#d23bed515a79a22d933ab53ab4ada19d05b2f08a"
3260+
dependencies:
3261+
fbemitter "^2.0.0"
3262+
fbjs "^0.8.0"
3263+
32473264
follow-redirects@0.0.7:
32483265
version "0.0.7"
32493266
resolved "http://r.cnpmjs.org/follow-redirects/download/follow-redirects-0.0.7.tgz#34b90bab2a911aa347571da90f22bd36ecd8a919"
@@ -5090,6 +5107,10 @@ lodash.cond@^4.3.0:
50905107
version "4.5.2"
50915108
resolved "http://r.cnpmjs.org/lodash.cond/download/lodash.cond-4.5.2.tgz#f471a1da486be60f6ab955d17115523dd1d255d5"
50925109

5110+
lodash.curry@^4.0.1:
5111+
version "4.1.1"
5112+
resolved "https://registry.npmjs.org/lodash.curry/-/lodash.curry-4.1.1.tgz#248e36072ede906501d75966200a86dab8b23170"
5113+
50935114
lodash.debounce@^4.0.0, lodash.debounce@^4.0.8:
50945115
version "4.0.8"
50955116
resolved "http://r.cnpmjs.org/lodash.debounce/download/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
@@ -5098,6 +5119,10 @@ lodash.flattendeep@^4.4.0:
50985119
version "4.4.0"
50995120
resolved "http://r.cnpmjs.org/lodash.flattendeep/download/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2"
51005121

5122+
lodash.flow@^3.3.0:
5123+
version "3.5.0"
5124+
resolved "https://registry.npmjs.org/lodash.flow/-/lodash.flow-3.5.0.tgz#87bf40292b8cf83e4e8ce1a3ae4209e20071675a"
5125+
51015126
lodash.get@^4.4.2:
51025127
version "4.4.2"
51035128
resolved "http://r.cnpmjs.org/lodash.get/download/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
@@ -6398,6 +6423,10 @@ punycode@^1.4.1:
63986423
version "1.4.1"
63996424
resolved "http://r.cnpmjs.org/punycode/download/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"
64006425

6426+
pure-color@^1.2.0:
6427+
version "1.3.0"
6428+
resolved "https://registry.npmjs.org/pure-color/-/pure-color-1.3.0.tgz#1fe064fb0ac851f0de61320a8bf796836422f33e"
6429+
64016430
q@^1.4.1:
64026431
version "1.5.0"
64036432
resolved "http://r.cnpmjs.org/q/download/q-1.5.0.tgz#dd01bac9d06d30e6f219aecb8253ee9ebdc308f1"
@@ -6828,6 +6857,15 @@ rc@^1.1.7:
68286857
minimist "^1.2.0"
68296858
strip-json-comments "~2.0.1"
68306859

6860+
react-base16-styling@^0.5.3:
6861+
version "0.5.3"
6862+
resolved "https://registry.npmjs.org/react-base16-styling/-/react-base16-styling-0.5.3.tgz#3858f24e9c4dd8cbd3f702f3f74d581ca2917269"
6863+
dependencies:
6864+
base16 "^1.0.0"
6865+
lodash.curry "^4.0.1"
6866+
lodash.flow "^3.3.0"
6867+
pure-color "^1.2.0"
6868+
68316869
react-content-loader@^1.5.1:
68326870
version "1.5.1"
68336871
resolved "https://registry.npmjs.org/react-content-loader/-/react-content-loader-1.5.1.tgz#6a3da8feaa99abf8c1dfd622e40603f31416bd0a"
@@ -6885,6 +6923,14 @@ react-intl@2.4.0:
68856923
intl-relativeformat "^2.0.0"
68866924
invariant "^2.1.1"
68876925

6926+
react-json-view@^1.14.0:
6927+
version "1.14.0"
6928+
resolved "https://registry.npmjs.org/react-json-view/-/react-json-view-1.14.0.tgz#c4b2b50c99a5b28c926e9bd670b096a390cdc29f"
6929+
dependencies:
6930+
flux "^3.1.3"
6931+
react-base16-styling "^0.5.3"
6932+
react-textarea-autosize "^5.1.0"
6933+
68886934
react-keydown@^1.9.4:
68896935
version "1.9.4"
68906936
resolved "http://r.cnpmjs.org/react-keydown/download/react-keydown-1.9.4.tgz#22718ac95edb64dd840dfc4350abf7e693ea0b7f"
@@ -6966,6 +7012,12 @@ react-test-renderer@16.0.0:
69667012
fbjs "^0.8.16"
69677013
object-assign "^4.1.1"
69687014

7015+
react-textarea-autosize@^5.1.0:
7016+
version "5.2.1"
7017+
resolved "https://registry.npmjs.org/react-textarea-autosize/-/react-textarea-autosize-5.2.1.tgz#2b78f9067180f41b08ac59f78f1581abadd61e54"
7018+
dependencies:
7019+
prop-types "^15.6.0"
7020+
69697021
react-toolbox@^2.0.0-beta.11:
69707022
version "2.0.0-beta.12"
69717023
resolved "https://registry.npmjs.org/react-toolbox/-/react-toolbox-2.0.0-beta.12.tgz#1d9dd7cc41e3b35dabdce5eb100a8068eee88c45"

0 commit comments

Comments
 (0)