Skip to content

createMemo should respect the equals value on its initial execution #2362

@snnsnn

Description

@snnsnn

A memo accept an initial value and the equals property via the options object to exert finer control over its update logic. However it does not respect the equals property on its initial execution but it should for consistency.

For the following example, 'some value' should never be assigned to the memo as it is not a valid value.

import { createEffect, createSignal, createMemo } from 'solid-js';

const [preferences, setPreferences] = createSignal({
  lang: 'en', theme: 'some value', fontSize: 'large',
});

const theme = createMemo(() => preferences().theme, 'light', {
  equals: (prev, curr) => {
    if (prev === curr) return true;
    if (prev === 'dark' && curr === 'light') return false;
    if (prev === 'light' && curr === 'dark') return false;
    return true;
  }
});

createEffect(() => console.log(theme()));

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions