@variousjs/create 0.3.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@variousjs/create",
3
- "version": "0.3.3",
3
+ "version": "0.5.0",
4
4
  "description": "VariousJS boilerplate",
5
5
  "bin": "bin/create.js",
6
6
  "publishConfig": {
@@ -33,9 +33,10 @@
33
33
  "@babel/preset-typescript": "^7.15.0",
34
34
  "@types/react": "^17.0.27",
35
35
  "@types/react-dom": "^17.0.9",
36
+ "@types/react-router-dom": "^5.3.3",
36
37
  "@typescript-eslint/eslint-plugin": "^4.31.2",
37
38
  "@typescript-eslint/parser": "^4.31.2",
38
- "@variousjs/various": "^0.4.1",
39
+ "@variousjs/various": "^1.0.0",
39
40
  "babel-loader": "^8.2.2",
40
41
  "css-loader": "^6.3.0",
41
42
  "eslint": "^7.32.0",
@@ -50,6 +51,7 @@
50
51
  "typescript": "^4.4.3",
51
52
  "webpack": "^5.54.0",
52
53
  "webpack-cli": "^4.8.0",
53
- "webpack-dev-server": "^4.3.0"
54
- }
54
+ "webpack-dev-server": "^4.7.3"
55
+ },
56
+ "dependencies": {}
55
57
  }
package/package.json.copy CHANGED
@@ -16,9 +16,10 @@
16
16
  "@babel/preset-typescript": "^7.15.0",
17
17
  "@types/react": "^17.0.27",
18
18
  "@types/react-dom": "^17.0.9",
19
+ "@types/react-router-dom": "^5.3.3",
19
20
  "@typescript-eslint/eslint-plugin": "^4.31.2",
20
21
  "@typescript-eslint/parser": "^4.31.2",
21
- "@variousjs/various": "^0.4.1",
22
+ "@variousjs/various": "^1.0.0",
22
23
  "babel-loader": "^8.2.2",
23
24
  "css-loader": "^6.3.0",
24
25
  "eslint": "^7.32.0",
@@ -33,7 +34,8 @@
33
34
  "typescript": "^4.4.3",
34
35
  "webpack": "^5.54.0",
35
36
  "webpack-cli": "^4.8.0",
36
- "webpack-dev-server": "^4.3.0"
37
+ "webpack-dev-server": "^4.7.3"
37
38
  },
39
+ "dependencies": {},
38
40
  "private": true
39
41
  }
@@ -1,10 +1,11 @@
1
1
  import React, { FC } from 'react'
2
- import { ComponentProps } from '@variousjs/various'
2
+ import { ComponentProps, Invoker } from '@variousjs/various'
3
+ import { useParams } from 'react-router-dom'
3
4
  import { Card, Button, message } from 'antd'
4
5
  import csses from './card.less'
5
6
 
6
- const H: FC<ComponentProps> & { getName: (e: string) => any } = (props) => {
7
- const id = props.$router?.match.params.id
7
+ const H: FC<ComponentProps> & { getName: Invoker } = (props) => {
8
+ const { id } = useParams<{ id: string }>()
8
9
 
9
10
  return (
10
11
  <div className={csses.container}>
@@ -40,6 +41,6 @@ const H: FC<ComponentProps> & { getName: (e: string) => any } = (props) => {
40
41
  )
41
42
  }
42
43
 
43
- H.getName = (e) => message.info(e)
44
+ H.getName = (e) => message.info(e.value)
44
45
 
45
46
  export default H
@@ -1,5 +1,5 @@
1
1
  import React, { Component } from 'react'
2
- import { ComponentProps, Store, Connect as CT } from '@variousjs/various'
2
+ import { ComponentProps, Store, Connect as CT, Invoker } from '@variousjs/various'
3
3
  import { Descriptions } from 'antd'
4
4
  import { Store as GlobalStore } from '../types'
5
5
 
@@ -9,16 +9,16 @@ type Connect = CT<S>
9
9
  const {
10
10
  createStore,
11
11
  connect,
12
- dispatch,
12
+ emit,
13
13
  getStore,
14
14
  } = new Store<S>()
15
15
 
16
16
  createStore({ value: 0 })
17
17
 
18
18
  class X extends Component<Connect & ComponentProps<GlobalStore>> {
19
- static setValue = async (value: number) => {
19
+ static setValue: Invoker = async ({ value }) => {
20
20
  const store = getStore()
21
- dispatch({ value: value + store.value }, true)
21
+ emit({ value: value + store.value }, true)
22
22
  }
23
23
 
24
24
  render() {
@@ -0,0 +1,54 @@
1
+ import React, { FC, useState, useEffect } from 'react'
2
+ import { ComponentProps } from '@variousjs/various'
3
+ import { useLocation, useHistory } from 'react-router-dom'
4
+ import { Radio, Badge, Button } from 'antd'
5
+ import { Config, Store } from '../types'
6
+
7
+ const H: FC<ComponentProps<Store, Config>> = (props) => {
8
+ const { pathname } = useLocation()
9
+ const history = useHistory()
10
+ const [path, setPath] = useState('')
11
+
12
+ useEffect(() => {
13
+ setPath(pathname)
14
+ }, [])
15
+
16
+ const onRouterChange = (e: any) => {
17
+ history.push(e.target.value)
18
+ setPath(e.target.value)
19
+ }
20
+
21
+ return (
22
+ <>
23
+ <Radio.Group
24
+ size="large"
25
+ value={path}
26
+ onChange={onRouterChange}
27
+ buttonStyle="solid"
28
+ >
29
+ {
30
+ props.$config.links.map(({ path, name }) => (
31
+ <Radio.Button key={path} value={path}>
32
+ {name}
33
+ </Radio.Button>
34
+ ))
35
+ }
36
+ </Radio.Group>
37
+ <div>
38
+ Store:
39
+ <Badge
40
+ style={{ marginLeft: 10 }}
41
+ count={props.$store.user.name}
42
+ />
43
+ <Button
44
+ style={{ marginLeft: 10 }}
45
+ onClick={() => props.$dispatch('card', 'getName', 'Card')}
46
+ >
47
+ Card Name
48
+ </Button>
49
+ </div>
50
+ </>
51
+ )
52
+ }
53
+
54
+ export default H
@@ -2,13 +2,13 @@ import { Actions } from '@variousjs/various'
2
2
  import { Store } from '../types'
3
3
 
4
4
  const actions: Actions<Store> = {
5
- async setName({ dispatch, getStore }, value) {
5
+ async setName({ emit, getStore }, { value }) {
6
6
  await new Promise((r) => setTimeout(r, 1000))
7
7
  const { user } = getStore()
8
8
  user.name = value
9
- dispatch({ user })
9
+ emit({ user })
10
10
  },
11
- getName({ getStore }) {
11
+ async getName({ getStore }) {
12
12
  const { user } = getStore()
13
13
  return user.name
14
14
  },
@@ -1,60 +1,20 @@
1
1
  import React, { Component, ComponentType } from 'react'
2
- import { ContainerProps, Router, Route } from '@variousjs/various'
3
- import { Radio, Badge, Button } from 'antd'
4
- import { Store, Config } from '../types'
2
+ import { ContainerProps } from '@variousjs/various'
3
+ import { HashRouter as Router, Route } from 'react-router-dom'
4
+ import { Config } from '../types'
5
5
  import csses from './entry.less'
6
6
 
7
- class Container extends Component<ContainerProps<Store, Config>> {
8
- state = {
9
- path: '/'
10
- }
11
-
12
- onRouterChange = (e: any) => {
13
- this.props.$router.history.push(e.target.value)
14
- this.setState({ path: e.target.value })
15
- }
16
-
17
- componentDidMount() {
18
- this.setState({ path: this.props.$router.location.pathname })
19
- }
20
-
7
+ class Container extends Component<ContainerProps<Config>> {
21
8
  render() {
22
- const { $component, $config, $store } = this.props
9
+ const { $component, $config } = this.props
10
+ const Top = $component('top')
23
11
 
24
12
  return (
25
13
  <div className={csses.container}>
26
- <div className={csses.top}>
27
- <Radio.Group
28
- size="large"
29
- value={this.state.path}
30
- onChange={this.onRouterChange}
31
- buttonStyle="solid"
32
- >
33
- {
34
- $config.links.map(({ path, name }) => (
35
- <Radio.Button key={path} value={path}>
36
- {name}
37
- </Radio.Button>
38
- ))
39
- }
40
- </Radio.Group>
41
-
42
- <div>
43
- Store:
44
- <Badge
45
- style={{ marginLeft: 10 }}
46
- count={$store.user.name}
47
- />
48
- <Button
49
- style={{ marginLeft: 10 }}
50
- onClick={() => this.props.$dispatch('card', 'getName', 'Card')}
51
- >
52
- Card Name
53
- </Button>
54
- </div>
55
- </div>
56
-
57
14
  <Router>
15
+ <div className={csses.top}>
16
+ <Top />
17
+ </div>
58
18
  {
59
19
  $config.pages.map(({ path, components }) => {
60
20
  const cs = () => components.map((name) => {
package/webpack/base.js CHANGED
@@ -8,6 +8,7 @@ const config = {
8
8
  // 组件入口定义
9
9
  card: path.join(__dirname, '../src/components/card.tsx'),
10
10
  next: path.join(__dirname, '../src/components/next.tsx'),
11
+ top: path.join(__dirname, '../src/components/top.tsx'),
11
12
  },
12
13
  output: {
13
14
  path: path.resolve(__dirname, '../demo/dist'),
@@ -26,6 +27,10 @@ const config = {
26
27
  root: 'ReactDOM',
27
28
  amd: 'react-dom',
28
29
  },
30
+ 'react-router-dom': {
31
+ root: 'ReactRouterDOM',
32
+ amd: 'react-router-dom',
33
+ },
29
34
  '@variousjs/various': {
30
35
  root: 'various',
31
36
  amd: '@variousjs/various',