Skip to content

Commit 4820d45

Browse files
authored
Merge pull request #24 from js2me/next-release
Next release
2 parents 2a9d5dc + b9b3a67 commit 4820d45

35 files changed

+760
-998
lines changed

.changeset/cuddly-horses-run.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"mobx-view-model": major
3+
---
4+
5+
removed all marked as deprecation properties and methods
6+
7+
- Removed `config` property in `ViewModelParams` interface (renamed to `vmConfig`)
8+
- Removed `linkStore` method in `ViewModelSimple` interface (renamed to `attachViewModelStore`)
9+
- Removed type `ComponentWithLazyViewModel` (renamed to `VMLazyComponent`)
10+
- Removed type `ComponentWithViewModel` (renamed to `VMComponent`)
11+
- Removed `params` property in `ViewModelBase` class (renamed to `vmParams`)

.changeset/dry-cycles-smell.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
"mobx-view-model": major
3+
---
4+
5+
modified global payload processing
6+
7+
Previosly `viewModelsConfig` haved the following configuration:
8+
9+
```ts
10+
comparePayload: 'strict',
11+
payloadObservable: 'ref',
12+
payloadComputed: false,
13+
```
14+
So it was a bit performance overhead. Now it is:
15+
```ts
16+
comparePayload: false,
17+
payloadComputed: 'struct',
18+
payloadObservable: 'ref',
19+
```
20+

.changeset/early-breads-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"mobx-view-model": minor
3+
---
4+
5+
added default implementation for `generateId` property in global `viewModelsConfig`

.changeset/forty-icons-wash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"mobx-view-model": patch
3+
---
4+
5+
fixed typings for `ParentViewModel` generic type argument for all interfaces/classes (support AnyViewModelSimple)

.changeset/pretty-ends-go.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
"mobx-view-model": minor
3+
---
4+
5+
`id` property now is optional for implementation for `ViewModelSimple` interface
6+
7+
Now you can do not implement `ViewModelSimple` interface to work with this library:
8+
9+
```tsx
10+
class MyVM {
11+
bar = '1'
12+
}
13+
...
14+
const model = useCreateViewModel(MyVM);
15+
return <div>{model.bar}</div>;
16+
```
17+
18+
```tsx
19+
class MyVM {
20+
foo = '1';
21+
}
22+
...
23+
const YouComponent = withViewModel(MyVM, ({ model }) => {
24+
return <div>{model.foo}</div>
25+
});
26+
```

.changeset/tiny-geese-attack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"mobx-view-model": minor
3+
---
4+
5+
`parentViewModel` property for `ViewModelSimple` interface

docs/.vitepress/config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export default defineConfig({
192192
link: '/recipes/observer-wrap-all-view-components',
193193
items: [
194194
{ text: 'Wrap in observer() all view components', link: '/recipes/observer-wrap-all-view-components' },
195+
{ text: 'Wrap view components in custom HOC', link: '/recipes/wrap-view-components-in-custom-hoc' },
195196
{ text: 'Integration with RootStore', link: '/recipes/integration-with-root-store' },
196197
]
197198
},

docs/api/view-models/view-model-simple.md

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ Use `ViewModelSimple` when:
1010
2. You prefer a simple, boilerplate-free class structure
1111
3. Your view model does not required advanced features like [`viewModels` access](/api/view-models/base-implementation.html#viewmodels) or complex lifecycle hooks.
1212

13-
## Implementation
14-
15-
### Requirements
16-
To implement `ViewModelSimple`, your class must:
17-
1. Define a unique `id` property to identify the instance (used for access in `ViewModelStore`)
18-
19-
2013
### Example
2114
```ts
2215
import { ViewModelSimple } from "mobx-view-model";
@@ -41,11 +34,58 @@ export class FruitViewModel implements ViewModelSimple {
4134
}
4235
```
4336

37+
::: tip defining `id` property is optional
38+
If you do not define the `id` property, a random id will be generated from `viewModelsConfig.generateId`
39+
:::
40+
41+
### Example without any implemented method from interface
42+
43+
```ts{4}
44+
import { ViewModelSimple } from "mobx-view-model";
45+
import { makeAutoObservable } from "mobx";
46+
47+
export class FruitViewModel {
48+
// Observable state
49+
fruit = "apple";
50+
51+
constructor() {
52+
// Initialize MobX observables
53+
makeAutoObservable(this);
54+
}
55+
56+
// Example action
57+
setFruit(newFruit: string) {
58+
this.fruit = newFruit;
59+
}
60+
}
61+
```
62+
63+
::: tip `implements ViewModelSimple` was removed
64+
Because TypeScript throws an error about not implementing at least one property or method of the `ViewModelSimple` interface.
65+
:::
66+
4467
## Usage in React
4568

46-
### Instance creation
69+
### Usage with [`withViewModel`](/react/api/with-view-model) HOC
4770

48-
Create instances using the [`useCreateViewModel`](/react/api/use-create-view-model) hook. This ensures proper lifecycle management and reactivity:
71+
```tsx
72+
import { observer } from "mobx-react-lite";
73+
import { withViewModel } from "mobx-view-model";
74+
import { FruitViewModel } from "./model";
75+
76+
export const FruitComponent = withViewModel(FruitViewModel, ({ model }) => {
77+
return (
78+
<div>
79+
<p>Current fruit: {model.fruit}</p>
80+
<button onClick={() => model.setFruit("banana")}>
81+
Change to Banana
82+
</button>
83+
</div>
84+
);
85+
});
86+
```
87+
88+
### Usage with [`useCreateViewModel`](/react/api/use-create-view-model) hook
4989

5090
```tsx
5191
import { observer } from "mobx-react-lite";
@@ -67,6 +107,8 @@ export const FruitComponent = observer(() => {
67107
});
68108
```
69109

110+
111+
70112
### Accessing Instances
71113
To retrieve an existing instance elsewhere in your app:
72114
1. Use the [`useViewModel`](/react/api/use-view-model) hook.

docs/api/view-models/view-models-config.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import { viewModelsConfig, ViewModelStoreBase } from 'mobx-view-model';
4141
viewModelsConfig.comparePayload = false;
4242
viewModelsConfig.payloadComputed = 'struct';
4343
viewModelsConfig.payloadObservable = 'ref';
44-
viewModelsConfig.wrapViewsInObserver = true;
4544

4645
viewModelsConfig.observable.viewModels.useDecorators = true; //false
4746
viewModelsConfig.observable.viewModelStores.useDecorators = true; // false
@@ -181,13 +180,15 @@ viewModelsConfig.processViewComponent = (Component) => {
181180
## `wrapViewsInObserver`
182181

183182
Wrap View components in [`observer()` MobX HOC](https://mobx.js.org/api.html#observer)
183+
This property is enabled by default.
184184

185-
Example:
186185

186+
You can turn off this behaviour by setting `wrapViewsInObserver` to `false`.
187+
Example:
187188
```tsx
188189
import { viewModelsConfig } from "mobx-view-model";
189190

190-
viewModelsConfig.wrapViewsInObserver = true;
191+
viewModelsConfig.wrapViewsInObserver = false;
191192
```
192193

193194
::: warning It works only for [`withViewModel` HOCs](/react/api/with-view-model)

docs/introduction/usage/detailed-configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { ViewModel as ViewModelBase } from 'mobx-view-model';
1717
1818
export interface ViewModel<
1919
Payload extends AnyObject = EmptyObject,
20-
ParentViewModel extends ViewModel<any> = ViewModel<any, any>,
20+
ParentViewModel extends ViewModel<any, any> | null = null,
2121
> extends ViewModelBase<Payload, ParentViewModel> {
2222
trackName: string;
2323
getTrackTime(): Date;
@@ -33,7 +33,7 @@ import { ViewModel } from './view-model';
3333
3434
export class ViewModelImpl<
3535
Payload extends AnyObject = EmptyObject,
36-
ParentViewModel extends ViewModel<any> = ViewModel<any>,
36+
ParentViewModel extends ViewModel<any, any> | null = null,
3737
>
3838
extends ViewModelBase<Payload, ParentViewModel>
3939
implements ViewModel<Payload, ParentViewModel>

0 commit comments

Comments
 (0)