Skip to content

Commit

Permalink
Merge pull request #56 from jfrere/main
Browse files Browse the repository at this point in the history
Recognise mapArray as a tracked scope
  • Loading branch information
joshwilsonvu authored Jan 3, 2023
2 parents 1db5114 + df40c38 commit 4c2d3af
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/reactivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ css`
color: ${f};
`;

function createCustomStore() {
const [store, updateStore] = createStore({});

return mapArray(
[],
// the second argument to mapArray is not tracked
(item) => store.path.to.field
);
}

```

### Valid Examples
Expand Down Expand Up @@ -508,6 +518,16 @@ function Component() {
);
}

function createCustomStore() {
const [store, updateStore] = createStore({});

return mapArray(
// the first argument to mapArray is a tracked scope
() => store.path.to.field,
(item) => ({})
);
}

```
<!-- AUTO-GENERATED-CONTENT:END -->

Expand Down
1 change: 1 addition & 0 deletions src/rules/reactivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
"createComputed",
"createSelector",
"untrack",
"mapArray",
],
callee.name
) ||
Expand Down
24 changes: 24 additions & 0 deletions test/rules/reactivity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ export const cases = run("reactivity", rule, {
}} />
);
}`,
// mapArray()
`function createCustomStore() {
const [store, updateStore] = createStore({});
return mapArray(
// the first argument to mapArray is a tracked scope
() => store.path.to.field,
(item) => ({})
);
}`,
],
invalid: [
// Untracked signals
Expand Down Expand Up @@ -646,5 +656,19 @@ export const cases = run("reactivity", rule, {
css\`color: \${f}\`;`,
errors: [{ messageId: "badSignal", line: 4 }],
},
// mapArray
{
code: `
function createCustomStore() {
const [store, updateStore] = createStore({});
return mapArray(
[],
// the second argument to mapArray is not tracked
(item) => store.path.to.field
);
}`,
errors: [{ messageId: "badUnnamedDerivedSignal", line: 7 }],
},
],
});

0 comments on commit 4c2d3af

Please sign in to comment.