Skip to content

Commit 4c2d3af

Browse files
authored
Merge pull request #56 from jfrere/main
Recognise mapArray as a tracked scope
2 parents 1db5114 + df40c38 commit 4c2d3af

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

docs/reactivity.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,16 @@ css`
227227
color: ${f};
228228
`;
229229

230+
function createCustomStore() {
231+
const [store, updateStore] = createStore({});
232+
233+
return mapArray(
234+
[],
235+
// the second argument to mapArray is not tracked
236+
(item) => store.path.to.field
237+
);
238+
}
239+
230240
```
231241

232242
### Valid Examples
@@ -508,6 +518,16 @@ function Component() {
508518
);
509519
}
510520

521+
function createCustomStore() {
522+
const [store, updateStore] = createStore({});
523+
524+
return mapArray(
525+
// the first argument to mapArray is a tracked scope
526+
() => store.path.to.field,
527+
(item) => ({})
528+
);
529+
}
530+
511531
```
512532
<!-- AUTO-GENERATED-CONTENT:END -->
513533

src/rules/reactivity.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
813813
"createComputed",
814814
"createSelector",
815815
"untrack",
816+
"mapArray",
816817
],
817818
callee.name
818819
) ||

test/rules/reactivity.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@ export const cases = run("reactivity", rule, {
223223
}} />
224224
);
225225
}`,
226+
// mapArray()
227+
`function createCustomStore() {
228+
const [store, updateStore] = createStore({});
229+
230+
return mapArray(
231+
// the first argument to mapArray is a tracked scope
232+
() => store.path.to.field,
233+
(item) => ({})
234+
);
235+
}`,
226236
],
227237
invalid: [
228238
// Untracked signals
@@ -646,5 +656,19 @@ export const cases = run("reactivity", rule, {
646656
css\`color: \${f}\`;`,
647657
errors: [{ messageId: "badSignal", line: 4 }],
648658
},
659+
// mapArray
660+
{
661+
code: `
662+
function createCustomStore() {
663+
const [store, updateStore] = createStore({});
664+
665+
return mapArray(
666+
[],
667+
// the second argument to mapArray is not tracked
668+
(item) => store.path.to.field
669+
);
670+
}`,
671+
errors: [{ messageId: "badUnnamedDerivedSignal", line: 7 }],
672+
},
649673
],
650674
});

0 commit comments

Comments
 (0)