Skip to content

New rule: store callbacks must use set param #267

Closed
@tivac

Description

@tivac

Description

Every now and then I forget how to properly use the "callback on subscriber" form of the built-in svelte stores, and end up writing something like this:

const store = writable(false, () => api.getData());

which doesn't work, because it should actually be written like this:

const store = writable(false, (set) => set(api.getData()));

Svelte REPL Example

A rule that ensures any readable or writable stores that use the callback form follow these rules would be great:

  1. Callback must accept a single parameter
  2. Somewhere within the callback function body it should execute that parameter as a function

I don't think we can get too much more descriptive about it, but even just those two checks would save me from debugging my bad stores.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions