diff --git a/docs/reactivity.md b/docs/reactivity.md index 6270068..b89811c 100644 --- a/docs/reactivity.md +++ b/docs/reactivity.md @@ -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 @@ -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) => ({}) + ); +} + ``` diff --git a/src/rules/reactivity.ts b/src/rules/reactivity.ts index bca3bcc..37ce7c6 100644 --- a/src/rules/reactivity.ts +++ b/src/rules/reactivity.ts @@ -813,6 +813,7 @@ const rule: TSESLint.RuleModule = { "createComputed", "createSelector", "untrack", + "mapArray", ], callee.name ) || diff --git a/test/rules/reactivity.test.ts b/test/rules/reactivity.test.ts index 704183b..2d80e69 100644 --- a/test/rules/reactivity.test.ts +++ b/test/rules/reactivity.test.ts @@ -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 @@ -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 }], + }, ], });