Skip to content

Commit 2d5d314

Browse files
feat: support mobx 7 and mobx-react-lite 5 (#25)
1 parent 82054bd commit 2d5d314

7 files changed

Lines changed: 73 additions & 46 deletions

File tree

‎.github/workflows/pr-check.yml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ jobs:
4040
- name: Check eslint
4141
run: npm run lint:check
4242

43-
- name: Test
43+
- name: Test (MobX 7 / mobx-react-lite 5)
4444
run: npm run test -- --coverage
4545

46+
- name: Install MobX 6 / mobx-react-lite 4
47+
run: npm install --no-save --ignore-scripts mobx@6.16.1 mobx-react-lite@4.1.1
48+
49+
- name: Test (MobX 6 / mobx-react-lite 4)
50+
run: npm test
51+
4652
- uses: actions/upload-artifact@v4
4753
with:
4854
name: coverage-lcov

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ It is built for apps that want explicit store ownership, SSR support, persistenc
4545
npm i @lomray/react-mobx-manager @lomray/consistent-suspense
4646
```
4747

48+
Supports MobX 6 (>=6.9.0) and 7 with mobx-react-lite 3, 4, or 5; consumers must choose compatible peers, as mobx-react-lite 5 requires MobX 7 and React 18+ (React 17 remains supported with mobx-react-lite 3 or 4).
49+
4850
## Documentation
4951

5052
Full documentation lives in [here](https://lomray-software.github.io/react-mobx-manager/)

‎__tests__/manager.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,42 @@ describe('Manager', () => {
7171
expect(manager.getStores().has('GlobalStore')).to.equal(true);
7272
});
7373

74+
it('should serialize mutations to auto-observable store classes', () => {
75+
class CounterStore {
76+
public static id = 'counter';
77+
public static isGlobal = true;
78+
79+
public count = 0;
80+
public nested = { values: [1] };
81+
82+
constructor() {
83+
makeAutoObservable(this, {}, { autoBind: true });
84+
}
85+
86+
public increment(): void {
87+
this.count += 1;
88+
this.nested.values.push(this.count + 1);
89+
}
90+
}
91+
92+
const manager = new Manager();
93+
const store = manager.getStore(CounterStore)!;
94+
95+
try {
96+
const initialState = manager.toJSON();
97+
98+
store.increment();
99+
100+
expect(manager.getStore(CounterStore)).to.equal(store);
101+
expect(initialState).to.deep.equal({ counter: { count: 0, nested: { values: [1] } } });
102+
expect(manager.toJSON()).to.deep.equal({
103+
counter: { count: 1, nested: { values: [1, 2] } },
104+
});
105+
} finally {
106+
manager.destroy();
107+
}
108+
});
109+
74110
it('should mark creation failure if parent store is not found', () => {
75111
class RelativeStore {
76112
public libStoreId?: string;

‎docs/examples/recipes.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ class UserStore {
1717
constructor() {
1818
makeObservable(this, {
1919
name: observable,
20-
setName: action.bound,
20+
setName: action,
2121
});
2222
}
2323

24-
public setName(name: string): void {
24+
public setName = (name: string): void => {
2525
this.name = name;
26-
}
26+
};
2727
}
2828

2929
const stores = {
@@ -50,13 +50,13 @@ class SomeOtherStore {
5050
constructor() {
5151
makeObservable(this, {
5252
value: observable,
53-
setValue: action.bound,
53+
setValue: action,
5454
});
5555
}
5656

57-
public setValue(value: string): void {
57+
public setValue = (value: string): void => {
5858
this.value = value;
59-
}
59+
};
6060
}
6161

6262
const stores = {

‎docs/guide/getting-started.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ class UserStore {
118118

119119
makeObservable(this, {
120120
name: observable,
121-
setName: action.bound,
121+
setName: action,
122122
});
123123
}
124124

125-
public setName(name: string): void {
125+
public setName = (name: string): void => {
126126
this.name = name;
127-
}
127+
};
128128
}
129129

130130
const stores = {
@@ -152,13 +152,13 @@ class SomeOtherStore {
152152
constructor() {
153153
makeObservable(this, {
154154
value: observable,
155-
setValue: action.bound,
155+
setValue: action,
156156
});
157157
}
158158

159-
public setValue(value: string): void {
159+
public setValue = (value: string): void => {
160160
this.value = value;
161-
}
161+
};
162162
}
163163

164164
const stores = {

‎package-lock.json‎

Lines changed: 13 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
"husky": "^9.1.7",
5959
"jsdom": "^29.0.0",
6060
"lint-staged": "^16.4.0",
61+
"mobx": "^7.0.3",
62+
"mobx-react-lite": "^5.0.3",
6163
"prettier": "^3.8.1",
6264
"rollup": "^4.59.0",
6365
"rollup-plugin-copy": "^3.5.0",
@@ -77,7 +79,7 @@
7779
"hoist-non-react-statics": ">=3.3.2",
7880
"lodash": ">=4.17.21",
7981
"mobx": ">=6.9.0",
80-
"mobx-react-lite": "^3 || ^4",
82+
"mobx-react-lite": "^3 || ^4 || ^5",
8183
"react": "^19 || ^18 || ^17"
8284
},
8385
"overrides": {

0 commit comments

Comments
 (0)