@vue-modeler/model 2.2.0-beta.7 → 2.2.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.
- package/README.md +25 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# vue-modeler/model
|
|
2
2
|
|
|
3
3
|
## What is @vue-modeler/model
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ A state management library based on models for [Vue.js](https://vuejs.org/). The
|
|
|
10
10
|
|
|
11
11
|
- **No global state store**. No store means no problems. State is encapsulated within the model and is reactive. Outside the model, it's only accessible for reading and observation.
|
|
12
12
|
- **Extremely simple API**: A model prototype is a standard class, actions are defined as standard methods with decorators. Create a model by calling a factory method — nothing more needed. Reactive properties and behavior are defined using the standard Vue API.
|
|
13
|
-
- **Supports shared models**.
|
|
13
|
+
- **Supports shared models**. Models can be shared across components. You can manage model instances using dependency injection or your own container pattern.
|
|
14
14
|
- **Follows DRY principle**. Actions have their own state. There's no need to write additional code to track action states. Focus instead on designing architecture and business logic.
|
|
15
15
|
- **Embraces OOP**. Model prototypes are classes, supporting inheritance, encapsulation, polymorphism, and destructors.
|
|
16
16
|
- **Complies with SOLID principles**. Encourages clean coding practices like composition of models, dependency injection via constructors, separation of interfaces, single responsibility, etc.
|
|
@@ -55,14 +55,14 @@ This library promises to simplify state management in [Vue.js](https://vuejs.org
|
|
|
55
55
|
|
|
56
56
|
## Installation
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
Then install @vue-modeler/model:
|
|
58
|
+
Install @vue-modeler/model:
|
|
61
59
|
|
|
62
60
|
```bash
|
|
63
61
|
npm add @vue-modeler/model
|
|
64
62
|
```
|
|
65
63
|
|
|
64
|
+
It is recommended to use it together with the dependency container [@vue-modeler/dc](https://github.com/vue-modeler/dc). For installation instructions and provider setup, see the [@vue-modeler/dc documentation](https://github.com/vue-modeler/dc?tab=readme-ov-file#installation).
|
|
65
|
+
|
|
66
66
|
## Usage Examples
|
|
67
67
|
|
|
68
68
|
### 1. Define Proto model
|
|
@@ -105,7 +105,7 @@ class User extends ProtoModel {
|
|
|
105
105
|
) {
|
|
106
106
|
super()
|
|
107
107
|
|
|
108
|
-
this.
|
|
108
|
+
this.init()
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
// Actions (async methods with @action decorator)
|
|
@@ -148,17 +148,30 @@ export const patchUser = async (dto: PatchDto): Promise<void> => {
|
|
|
148
148
|
}
|
|
149
149
|
```
|
|
150
150
|
|
|
151
|
-
### 3.
|
|
151
|
+
### 3. Create model provider
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
import { model } from '@vue-modeler/model'
|
|
153
|
+
Using `@vue-modeler/dc` (recommended):
|
|
155
154
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
```typescript
|
|
156
|
+
import { provider } from '@vue-modeler/dc'
|
|
157
|
+
import { User } from './user-model'
|
|
158
|
+
import { fetchUser, patchUser } from './api'
|
|
159
|
+
|
|
160
|
+
export const useUser = provider(() => User.model({
|
|
161
|
+
fetchUser,
|
|
162
|
+
patch: patchUser
|
|
159
163
|
}))
|
|
160
164
|
```
|
|
161
165
|
|
|
166
|
+
Or without dependency container:
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
export const useUser = () => User.model({
|
|
170
|
+
fetchUser,
|
|
171
|
+
patch: patchUser
|
|
172
|
+
})
|
|
173
|
+
```
|
|
174
|
+
|
|
162
175
|
### 4. Using Models in Vue Components
|
|
163
176
|
|
|
164
177
|
```html
|