Skip to content

Commit c1e0c0b

Browse files
committed
fix(store-get-state-return-object-to-flat): null guard
1 parent dd665de commit c1e0c0b

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ Install with [npm](https://www.npmjs.com/):
1818

1919
```bash
2020
# Install to global
21-
npm install -g jscodeshift
22-
# Install to local
23-
npm install @almin/migration-tools
21+
npm install -g jscodeshift @almin/migration-tools
2422
# Run migration scripts
2523
## Target: your almin store files
26-
jscodeshift -t ./node_modules/@almin/scripts/store-get-state-return-object-to-flat.js <path>
24+
### Notice: Use this script with `--run-in-band` arguments(serial running)
25+
jscodeshift --run-in-band -t `npm root -g`/@almin/migration-tools/scripts/store-get-state-return-object-to-flat.js <path>
2726
```
2827

2928
Store#getState return value migration.
@@ -59,12 +58,10 @@ The `almin-store-state-mapping.json` is used with next script(Convert StoreGroup
5958

6059
```bash
6160
# Install to global
62-
npm install -g jscodeshift
63-
# Install to local
64-
npm install @almin/migration-tools
61+
npm install -g jscodeshift @almin/migration-tools
6562
# Run migration scripts
6663
## Target: your almin StoreGroup file
67-
jscodeshift -t ./node_modules/@almin/scripts/store-group-arguments.js <path>
64+
jscodeshift -t `npm root -g`/@almin/migration-tools/scripts/store-group-arguments.js <path>
6865
```
6966

7067
Migrate StoreGroup constructor arguments.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {Store} from "almin";
2+
import CartState from "./CartState";
3+
export default class CartStore extends Store {
4+
/**
5+
* @param {CartRepository} cartRepository
6+
*/
7+
constructor(cartRepository) {
8+
super();
9+
this.state = new CartState();
10+
cartRepository.onChange(cart => {
11+
const newState = new CartState(cart);
12+
if (this.state !== newState) {
13+
this.state = newState;
14+
this.emitChange();
15+
}
16+
});
17+
}
18+
19+
getState() {
20+
return {
21+
CartState: this.state
22+
};
23+
}
24+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {Store} from "almin";
2+
import CartState from "./CartState";
3+
export default class CartStore extends Store {
4+
/**
5+
* @param {CartRepository} cartRepository
6+
*/
7+
constructor(cartRepository) {
8+
super();
9+
this.state = new CartState();
10+
cartRepository.onChange(cart => {
11+
const newState = new CartState(cart);
12+
if (this.state !== newState) {
13+
this.state = newState;
14+
this.emitChange();
15+
}
16+
});
17+
}
18+
19+
getState() {
20+
return this.state;
21+
}
22+
}

scripts/__tests__/store-get-state-return-object-to-flat.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('store-getState', () => {
1111
__dirname,
1212
'store-get-state-return-object-to-flat',
1313
{
14-
dry: true
14+
dry: false
1515
},
1616
`store-get-state-return-object-to-flat/${ test }`
1717
)

scripts/store-get-state-return-object-to-flat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module.exports = function(file, api, options) {
7878
return path.value.properties[0].value;
7979
})
8080
.toSource();
81-
if (!options.dry) {
81+
if (!options.dry && stateName && filePath) {
8282
updateState(outputJSONPath, stateName, filePath);
8383
}
8484
return replaced;

0 commit comments

Comments
 (0)