Function cell

  • This is not a core part of ember-resources, but is a useful utility when working with Resources. This utility is still under the broader library's SemVer policy. Additionally, the "Cell" is a core concept in Starbeam. See Cells in Starbeam

    Small state utility for helping reduce the number of imports when working with resources in isolation.

    The return value is an instance of a class with a single @tracked property, current. If current is a boolean, there is a toggle method available as well.

    For example, a Clock:

    import { resource, cell } from 'ember-resources';

    const Clock = resource(({ on }) => {
    let time = cell(new Date());
    let interval = setInterval(() => time.current = new Date(), 1000);

    on.cleanup(() => clearInterval(interval));

    let formatter = new Intl.DateTimeFormat('en-US', {
    hour: 'numeric',
    minute: 'numeric',
    second: 'numeric',
    hour12: true,
    });

    return () => formatter.format(time.current);
    });

    <template>
    It is: <time>{{Clock}}</time>
    </template>

    Additionally, cells can be directly rendered:

    import { resource, cell } from 'ember-resources';

    const value = cell(0);

    <template>
    {{value}}
    </template>

    Type Parameters

    • Value = unknown

    Parameters

    • Optional initialValue: Value

    Returns Cell<Value>

Generated using TypeDoc