solid-alive 0.3.3 → 0.3.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +119 -98
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-alive",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "author": "1iuxs",
5
5
  "description": "solid-alive",
6
6
  "type": "module",
package/readme.md CHANGED
@@ -1,155 +1,176 @@
1
1
  ## solid-alive
2
2
 
3
3
  ### 安装(install)
4
- - pnpm add solid-alive / npm i solid-alive / yarn add solid-alive
4
+
5
+ - pnpm add solid-alive / npm i solid-alive / yarn add solid-alive
6
+
5
7
  ### 描述(describe)
6
- - 用于 solid 组件缓存,只测试过2级路由缓存
7
- - AliveProvider
8
- - include : 数组, ['/','/about'], 当数据变少时, 会自动去删除少的数据缓存
9
- - 在 useAlive
10
- - onActivated
11
- - onDeactivated
12
8
 
13
- - 子父 缓存/删除 问题
14
- - 如果某组件下有子组件,在父的 aliveTransfer中,
15
- 第三个参数,为对象 写上子组件的唯一id: {children:['/childrenId','asf',...]}
9
+ - 用于 solid 组件缓存,只测试过 2 级路由缓存
10
+ - AliveProvider
11
+ - include : 数组, 默认不缓存, ['/','/about'], 当数据变少时, 会自动去删除少的数据缓存
12
+ - transitionEnterName 动画, class 名称, 案例下面
13
+ - onActivated
14
+ - onDeactivated
15
+ - useAliveFrozen: hooks 在新增路由时 ,暂时不响应 路由数据变化
16
+ 使用: var aliveFrozen = useAliveFrozen()
17
+ - nextTick
16
18
 
19
+ ### 使用(use)
17
20
 
21
+ 1 /index.tsx,AliveProvider 将 app 包裹
18
22
 
19
- ### 使用(use)
20
- 1 /index.tsx,AliveProvider将app 包裹
21
- ```jsx
23
+ ```jsx
22
24
  import { render } from 'solid-js/web'
23
25
  import App from './App'
24
26
  import { AliveProvider } from 'solid-alive'
27
+ // import styles from "css.path"
25
28
 
26
29
  const root = document.getElementById('root')
27
30
 
28
- render(() =>
29
- <AliveProvider include={[]}>
30
- <App />
31
- </AliveProvider>
31
+ render(() =>
32
+ // cache id = '/' ;
33
+ // transitionEnterName={styles.appear}
34
+ <AliveProvider include={['/']} transitionEnterName="xxx">
35
+ <App />
36
+ </AliveProvider>
32
37
  , root!)
33
- ```
38
+ ```
34
39
 
35
- 2 /App.tsx ,在 solid-alive 中 有 aliveTransfer, 参数: JSX , id:string, children?:[string..]
36
- ```jsx
37
- import { Route, Router } from '@solidjs/router';
38
- import { aliveTransfer } from 'solid-alive';
40
+ transitionEnterName 动画 css
39
41
 
40
- import Home from './views/Home';
41
- import Client from './views/Client';
42
- import About from './views/About';
43
- import Team from './views/Blog/Team';
44
- import Blog from './views/Blog';
45
- import Single from './views/Blog/Single';
42
+ ```css
43
+ .appear {
44
+ animation: _appear 0.3s ease-in;
45
+ -webkit-animation: _appear 0.3s ease-in;
46
+ }
47
+
48
+ @keyframes _appear {
49
+ 0% {
50
+ opacity: 0;
51
+ }
52
+ 100% {
53
+ opacity: 1;
54
+ }
55
+ }
56
+ ```
46
57
 
58
+ 2 /App.tsx ,在 solid-alive 中 有 aliveTransfer, 参数: JSX , id:string, children?:[string..]
47
59
 
48
- const HomeTransfer = aliveTransfer(Home, '/'),
49
- AboutTsf = aliveTransfer(About, '/about'),
50
- BlogTsf = aliveTransfer(Blog, '/blog', ['/contact', 'single']),
51
- SingleTsf = aliveTransfer(Single,'single')
60
+ ```jsx
61
+ import { Route, Router } from "@solidjs/router"
62
+ import { aliveTransfer } from "solid-alive"
63
+
64
+ import Home from "./views/Home"
65
+ import Client from "./views/Client"
66
+ import About from "./views/About"
67
+ import Team from "./views/Blog/Team"
68
+ import Blog from "./views/Blog"
69
+ import Single from "./views/Blog/Single"
70
+ import Contact from "./views/Contact"
71
+
72
+ const HomeTransfer = aliveTransfer(Home, "/"),
73
+ AboutTsf = aliveTransfer(About, "/about"),
74
+ BlogTsf = aliveTransfer(Blog, "/blog", ["single", "/contact"]),
75
+ SingleTsf = aliveTransfer(Single, "single"),
76
+ ContactTsf = aliveFransfer(Contact, "/contact")
52
77
 
53
78
  export default function App() {
54
79
  return (
55
80
  <Router>
56
- {/* 这个Client 只是用于标签加跳转的,使用时可不用 */}
57
- <Route component={Client}>
58
- <Route component={Home} path={'/'} />
59
- {/* 单个缓存 single */}
60
- <Route component={AboutTsf} path={'/about'} />
61
- {/* 父子 缓存 Parent Child Nesting */}
62
- <Route component={BlogTsf} path={'/blog'}>
63
- <Route component={SingleTsf} path={'single'} />
64
- </Route>
81
+ <Route component={Home} path={"/"} />
82
+ {/* 单个缓存 single */}
83
+ <Route component={AboutTsf} path={"/about"} />
84
+ {/* 父子 缓存 Parent Child Nesting */}
85
+ <Route component={BlogTsf} path={"/blog"}>
86
+ <Route component={SingleTsf} path={"single"} />
87
+ <Route component={ContactTsf} path={"contact"} />
65
88
  </Route>
66
89
  </Router>
67
- );
68
- }
69
- ```
70
- 3 父 /views/Blog/index.tsx
71
- ```jsx
72
- export default function Blog(props: any) {
73
- return (
74
- <div>
75
- <h2>Blog</h2>
76
- <div>{props.children}</div>
77
- </div>
78
- );
90
+ )
79
91
  }
80
92
  ```
81
93
 
82
- - 子 /views/Blog/Single/index.tsx
83
- ```tsx
84
- import { onActivated,onDeactivated,useAlive, AliveComponent } from "solid-alive"
85
-
86
- export default function Single() {
87
- const { removeAliveElements,aliveFrozen } = useAlive()
88
-
94
+ 3 父 /views/Blog/index.tsx
89
95
 
96
+ ```jsx
97
+ import { onActivated, onDeactivated, useAliveFrozen } from "@/alives"
98
+ export default function Blog(props: any) {
99
+ // 新增路由时用
100
+ const aliveFrozen = useAliveFrozen()
101
+ const addRouter = () => {
102
+ aliveFrozen()
103
+ // add route....
104
+ }
90
105
  //todo call 这个会被调用
91
- onActivated(()=>{
92
- console.log('Single-activeated-1')
106
+ onActivated(() => {
107
+ console.log("Blog-activeated-1")
93
108
  })
94
-
109
+
95
110
  //todo call 也会被调用
96
- onActivated(()=>{
97
- console.log('Single-activeated-2')
111
+ onActivated(() => {
112
+ console.log("Blog-activeated-2")
98
113
  })
99
114
  // 缓存离开,
100
- onDeactivated(()=>{
101
- console.log('Single-deactivated')
115
+ onDeactivated(() => {
116
+ console.log("Blog-deactivated")
102
117
  })
118
+
119
+ // createEffect(()=>{
120
+ // console.log('blog-createEffect')
121
+ // })
122
+
103
123
  return (
104
124
  <div>
105
- <h2>Single</h2>
106
- <input type="text" style={{ border: '2px solid red' }} />
125
+ <h2>Blog</h2>
126
+ {props.children}
107
127
  </div>
108
128
  )
109
129
  }
110
130
  ```
111
131
 
112
- 3 动态生成 路由
132
+ 2 动态生成 路由
133
+
113
134
  ```tsx
114
135
  /** App.tsx */
115
- import { createEffect, lazy, type Component } from 'solid-js'
116
- import { Route, Router } from '@solidjs/router'
117
- import { useAlive, aliveTransfer } from "solid-alive"
136
+ import { createEffect, lazy, type Component } from "solid-js"
137
+ import { Route, Router } from "@solidjs/router"
138
+ import { aliveTransfer } from "solid-alive"
118
139
 
119
140
  const modules = import.meta.glob<{ default: Component<any> }>([
120
- './views/**/**.tsx',
121
- './views/**.tsx'
141
+ "./views/**/**.tsx",
142
+ "./views/**.tsx",
122
143
  ])
123
144
 
124
- const transferRouter = (data: MenuData[]) =>
125
- data.flatMap(item => {
126
- let module = modules[`./views${item.realPath}`]
127
- if (!module) return []
128
- const Transfer = aliveTransfer(
129
- lazy(module),
130
- item.path,
131
- item.children?.map(item => item.path)
132
- )
133
- return (
134
- <Route component={Transfer} path={item.path.split('/').at(-1)}>
135
- {item.children ? transferRouter(item.children) : null}
136
- </Route>
137
- )
138
- })
145
+ const transferRouter = (data: IMenuData[]) => (
146
+ <For each={data}>
147
+ {(item) => {
148
+ var module = modules[`./views${item.realPath.replace(/\.\./g, "")}`]
149
+ if (!module) return []
150
+ return (
151
+ <Route
152
+ component={aliveTransfer(
153
+ lazy(module),
154
+ item.path,
155
+ item.children?.map((item) => item.path)
156
+ )}
157
+ path={item.path.split("/").at(-1)}
158
+ >
159
+ {item.children ? transferRouter(item.children) : null}
160
+ </Route>
161
+ )
162
+ }}
163
+ </For>
164
+ )
139
165
 
140
166
  const App: Component = () => {
141
- const { aliveFrozen } = useAlive()
142
-
143
- const [data, setData] = createStore<MenuData[]>([])
144
167
  return (
145
168
  <Router>
146
- <Route component={Client}>
147
- {/* treeDatadata变成 树结构数据 */}
148
- {transferRouter(treeData(data))}
149
- </Route>
169
+ {/* treeData 将 data变成 树结构数据 */}
170
+ {transferRouter(treeData(data))}
150
171
  </Router>
151
172
  )
152
173
  }
153
174
 
154
175
  export default App
155
- ```
176
+ ```