Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release Preview (beta) #770

Merged
merged 1 commit into from
Mar 4, 2023
Merged

Release Preview (beta) #770

merged 1 commit into from
Mar 4, 2023

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Feb 23, 2023

This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

main is currently in pre mode so this branch has prereleases rather than normal releases. If you want to exit prereleases, run changeset pre exit on main.

⚠️⚠️⚠️⚠️⚠️⚠️

Releases

[email protected]

Major Changes

  • #715 e8155b2 Thanks @NullVoxPopuli! - Drop support for TypeScript < 4.8 in order to support Glint.

  • #778 901ae9a Thanks @NullVoxPopuli! - The map utility resource has changed its first type-argument for better inference.

    The utility already supported inference, so this change should not impact too many folks.

    When explicit type-arguments were specified,

    class Demo {
      // previously
      a = map<Element>(this, {
        data: () => [
          /* ... list of Element(s) ... */
        ],
        map: (element) => {
          /* some transform */
        },
      });
    
      // now
      a = map<Element[]>(this, {
        data: () => [
          /* ... list of Element(s) ... */
        ],
        map: (element) => {
          /* some transform */
        },
      });
    }

    This is advantageous, because with @tsconfig/ember, the option noUncheckedIndexedAccess
    is enabled by default. This is a great strictness / quality option to have enabled,
    as arrays in javascript are mutable, and we can't guarantee that they don't change between
    index-accesses.

    However the map utility resource explicitly disallows the indicies to get out of sync
    with the source data.

    But!, with noUncheckedIndexedAccess, you can only infer so much before TS goes the safe route,
    and makes the returned type X | undefined.

    For example, in these type-tests:

    import { map } from "ember-resources/util/map";
    import { expectType } from "ts-expect";
    
    const constArray = [1, 2, 3];
    
    b = map(this, {
      data: () => constArray,
      map: (element) => {
        expectType<number>(element);
        return element;
      },
    });
    
    // index-access here is *safely* `| undefined`, due to `constArray` being mutable.
    expectType<number | undefined>(b[0]);
    expectType<number | undefined>(b.values()[0]);
    
    // but when we use a const as const array, we define a tuple,
    // and can correctly infer and return real values via index access
    const tupleArray = [1, 2, 3] as const;
    
    c = map(this, {
      data: () => tupleArray,
      map: (element) => {
        expectType<number>(element);
        return element;
      },
    });
    
    // No `| undefined` here
    expectType<number>(c[0]);
    expectType<number>(c.values()[0]);
  • #779 a471d9b Thanks @NullVoxPopuli! - trackedFunction has a new API and thus a major version release is required.

    Work by @lolmaus

    tl;dr: the breaking changes:

    • no more manual initial value
    • isResolved is only true on success
    • isError has been renamed to isRejected
    • isLoading has been removed as it was redundant

    other changes:

    • trackedFunction is a wrapper around ember-async-data's TrackedAsyncData
    • behavior is otherwise the same

    NOTE: trackedFunction is an example utility of how to use auto-tracking with function invocation,
    and abstract away the various states involved with async behavior. Now that the heavy lifting is done by ember-async-data,
    trackedFunction is now more of an example of how to integrated existing tracked utilities in to resources.


    Migration

    Previously, trackedFunction could take an initial value for its second argument.

    class Demo {
      foo = trackedFunction(this, "initial value", async () => {
        /* ... */
      });
    }

    This has been removed, as initial value can be better maintained and made more explicit
    in user-space. For example:

    class Demo {
      foo = trackedFunction(this, async () => {
        /* ... */
      });
    
      get value() {
        return this.foo.value ?? "initial value";
      }
    }

    Or, in a template:

    {{#if this.foo.value}}
      {{this.foo.value}}
    {{else}}
      initial displayed content
    {{/if}}

    Or, in gjs/strict mode:

    const withDefault = (value) => value ?? 'initial value';
    
    class Demo extends Component {
      foo = trackedFunction(this, async () => { /* ... */ });
    
      <template>
        {{withDefault this.foo.value}}
      </template>
    }

    Previously, the isResolved property was true for succesful and error states

    Now, isResolved is only true when the function passed to trackedFunction has succesfully
    completed.

    To have behavior similar to the old behavior, you may want to implement your own isFinished getter:

    class Demo {
      foo = trackedFunction(this, async () => {
        /* ... */
      });
    
      get isFinished() {
        return this.foo.isResolved || this.foo.isRejected;
      }
    }

Minor Changes

Patch Changes

@github-actions github-actions bot force-pushed the changeset-release/main branch 8 times, most recently from 60458a4 to e7bb10c Compare March 4, 2023 00:32
@github-actions github-actions bot changed the title Release Preview Release Preview (beta) Mar 4, 2023
@github-actions github-actions bot force-pushed the changeset-release/main branch 2 times, most recently from 5d242e9 to 149f302 Compare March 4, 2023 13:57
@NullVoxPopuli NullVoxPopuli merged commit 1e844d4 into main Mar 4, 2023
@NullVoxPopuli NullVoxPopuli deleted the changeset-release/main branch March 4, 2023 14:08
@NullVoxPopuli NullVoxPopuli mentioned this pull request Mar 4, 2023
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant