You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 26, 2023. It is now read-only.
*Vue States is a state management system for Vue.js.*
6
+
7
+
_Vue States is a state management system for Vue.js._
7
8
8
9
Checkout the examples at https://github.com/JohannesLamberts/vue-states-examples.
9
10
10
11
You might want to choose to use Vue States for:
11
12
12
13
-**Simplicity** <br />Just `this.MyModel.key` and `this.MyModel.update(payload)`. No huge API, that exposes implementation details like `state, getters, commit, dispatch`.<br />Hot Module Replacement and Lazy-Loading made easy.
13
-
-**Flexible scope**<br />It is designed to support application-wide and local state, and can still be hydrated from SSR or localStorage.
14
+
-**Flexible scope**<br />It is designed to support application-wide and local state, and can still be hydrated from SSR or localStorage.
14
15
-**Learning & refactoring**<br />The state is composed of Vue components. That means: almost no new APIs and patterns to learn, plus seamless refactoring of your application.
15
16
-**Power**<br />All plugins and native Vue capabilities are accessible by design, without any configuration ( `this.$router, this.$apollo, created()...` ).
16
17
-**[History](#history)**<br />In combination with [Vue History](https://github.com/sumcumo/vue-history) you get a detailed view of what's going on, even for complex scenarios, async processes, error tracking and deeply nested call chains.
17
18
18
-
*This package was released just recently. Feedback is highly welcome.*
19
+
_This package was released just recently. Feedback is highly welcome._
19
20
20
21
## Installation
21
22
22
-
The plugin can be installed without any further options:
23
+
The plugin can be installed without any further options:
23
24
24
25
```javascript
25
26
importVueStatesfrom'@sum.cumo/vue-states'
@@ -29,23 +30,20 @@ Vue.use(VueStates)
29
30
...or with additional configuration:
30
31
31
32
```javascript
32
-
Vue.use(
33
-
VueStates,
34
-
{
35
-
// equal to Vue mixins, will be applied to every created model
36
-
mixins: [],
37
-
38
-
// a models state will be restored
39
-
// if an old match (same name and modelId) is found
40
-
// can be used to preserve state during hot module replacement 🚀
@@ -239,7 +225,7 @@ import { Registry } from '@sum.cumo/vue-states'
239
225
240
226
exportdefaultasyncfunctioncreateApp() {
241
227
// ...
242
-
228
+
243
229
constmodelRegistry=newRegistry()
244
230
245
231
if (typeofwindow!=='undefined'&&window.__VUE_STATES__) {
@@ -262,20 +248,20 @@ For import/export to work you will need to provide an id to further identify the
262
248
263
249
```javascript
264
250
exportdefaultmodelId=> ({
265
-
// the combination of name and modelId must be unique at any given time
266
-
modelId,
251
+
// the combination of name and modelId must be unique at any given time
252
+
modelId,
267
253
268
-
data() {
269
-
return {
270
-
counter:0,
271
-
}
272
-
},
273
-
274
-
methods: {
275
-
increment() {
276
-
this.counter+=1
277
-
},
254
+
data() {
255
+
return {
256
+
counter:0,
257
+
}
258
+
},
259
+
260
+
methods: {
261
+
increment() {
262
+
this.counter+=1
278
263
},
264
+
},
279
265
})
280
266
```
281
267
@@ -287,16 +273,16 @@ export default {
287
273
someIdentifier: {
288
274
type:String,
289
275
required:true,
290
-
}
276
+
},
291
277
},
292
-
293
-
// you may also pass a function that is evaluated in the created hook
278
+
279
+
// you may also pass a function that is evaluated in the created hook
294
280
// and receives the hosting Vue component as context
295
281
models() {
296
282
return {
297
283
Counter:createCounter(this.someIdentifier),
298
284
}
299
-
}
285
+
},
300
286
}
301
287
```
302
288
@@ -305,10 +291,7 @@ export default {
305
291
Nuxt.js gets confused by the models attached to the component tree. The errors can be resolved by adding `abtract: true` to all models (which however makes them invisible in the developer tools).
@@ -321,6 +304,6 @@ Licensed under the Apache License, Version 2.0 (the “License”); you may not
321
304
322
305
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
323
306
324
-
----
307
+
---
325
308
326
309
[Learn more about sum.cumo](https://www.sumcumo.com/en) and [work on open source projects](https://www.sumcumo.com/jobs), too!
0 commit comments