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

Create public import for uniqueId helper #20171

Closed
wants to merge 8 commits into from

Conversation

TechieQian
Copy link
Contributor

Adds public import for uniq-id

#20165

Copy link
Member

@bertdeblock bertdeblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to add an entry here?

packages/@ember/helper/index.ts Outdated Show resolved Hide resolved
@TechieQian TechieQian marked this pull request as draft August 29, 2022 20:04
@chriskrycho chriskrycho changed the title re-export uniqId re-export uniqueId Aug 30, 2022
@chriskrycho chriskrycho changed the title re-export uniqueId Create public import for uniqueId helper Aug 30, 2022
@TechieQian TechieQian marked this pull request as ready for review August 30, 2022 21:12
packages/ember/index.js Outdated Show resolved Hide resolved
Copy link
Contributor

@chriskrycho chriskrycho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for working on this! We talked about it today at the Framework Core Team meeting, and noted that there were a couple gaps between the RFC which introduced unique-id and the actual implementation:

  • the introduction of plain old functions as helpers via RFC #0756: Default Helper Manager
  • the lack of an import in support of template strict mode and first-class component templates
  • the lack of a clear definition of

These are not your responsibility to address as part of this change, however, so we’ve come up with a path that provides the public import we need for <template> support, as outlined in the rest of this review.

If you’re interested, we need to do some work separately to solve those issues, by writing a small RFC which defines how we should approach helpers like this going forward, not least so they can be usable as normal JS functions without the extra bits you'll see below. Let me know if you’re interested in that: @wycats is available to help get that written!

Again, though, the only things we need to do to land this are to address the comments in the review. Thanks for doing this!

Comment on lines 21 to 22
let first = uniqueId();
let second = uniqueId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, then, you should be able to use those new imports like this:

Suggested change
let first = uniqueId();
let second = uniqueId();
let first = getValue(invokeHelper({}, uniqueId()));
let second = getValue(invokeHelper({}, uniqueId()));

The rest of the test should “just work” once you’ve added that in. This gets at the bit we’ll need to do follow-up work around—this obviously isn’t a great experience in JS! However, we don’t need to tackle that here, and it needs some broader design work!

Copy link
Contributor Author

@TechieQian TechieQian Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm, assuming we want just uniqueId since its not fn. So trying
getValue(invokeHelper({}, uniqueId) I get the following very intentional sounding error.

Died on test #1: Found a helper manager, but it was an internal built-in helper manager. `invokeHelper` does not support internal helpers yet.

I dug into @glimmer/runtime a bit, and it seems like we just determine this to be an internal built-in helper manager based on the fact that it takes in a type function.

  function invokeHelper(context, definition, computeArgs) {
    ... 

    if (true
    /* DEBUG */
    && typeof internalManager === 'function') {
      throw new Error('Found a helper manager, but it was an internal built-in helper manager. `invokeHelper` does not support internal helpers yet.');
    }

Here's the minimal repro of the situation:

   let myRef = internalHelper(() => createConstRef('foo', 'unique-id'));
    try {
      invokeHelper({}, myRef);
    } catch (ex) {
      console.error('see error:', ex);
    }

I am missing some context of what an internal helper is vs external(?). Had this just been a Reference, I see there are helper functions like valueForRef(createConst('foo', 'unique-id')) // => foo

packages/ember/index.js Outdated Show resolved Hide resolved
packages/ember/index.js Outdated Show resolved Hide resolved
@chriskrycho
Copy link
Contributor

Sorry, forgot about this in the midst of a bunch of other things—just kicked back off CI for it and will take another review pass later today!

@TechieQian
Copy link
Contributor Author

TechieQian commented Oct 1, 2022

Sorry, forgot about this in the midst of a bunch of other things—just kicked back off CI for it and will take another review pass later today!

Hey @chriskrycho , pls let me know how we should proceed here. As it stands, I dont think we could just use invokeHelper per my comment on the suggestion. Happy to dig further!

@chriskrycho
Copy link
Contributor

Yeah, I noted that and will bring it up with folks next week! Thanks for checking in. Just had end-of-quarter extra stuff these past couple weeks.

@wycats
Copy link
Member

wycats commented Oct 25, 2022

I met with @TechieQian and we discussed the bulk of the open issues here.

I took some (very incomplete and possibly cryptic) notes during the meeting: https://gist.github.com/wycats/6800716eb6744f63d9b9396670d5c625

The next steps are to meet about this in a spec meeting. @TechieQian is available to attend whenever the discussion is on the agenda. It's a pretty meaty topic, so we'll want to allocate plenty of time to discuss it.

@wycats
Copy link
Member

wycats commented Oct 25, 2022

One observation that we made: since "functions as helpers" is now the law of the land, it basically works to export the uniqueId JS function and have people use it in <template>.

However, we'd need to be sure that we guarantee that when a function with no autotracking dependencies is used as a helper, it's never spuriously re-evaluated. I believe that this is the case today, but we'd need to be really sure.

Copy link
Member

@bertdeblock bertdeblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good AFAICT!

@chriskrycho
Copy link
Contributor

  1. This needs a rebase.
  2. Last time we were here, CI was failing, and there were open questions about how to get it the rest of the way across the line. It was not clear to me from @wycats' comment above whether it's actually unblocked here or not.

@TechieQian
Copy link
Contributor Author

TechieQian commented Feb 15, 2023 via email

@NullVoxPopuli
Copy link
Sponsor Contributor

I believe that this is the case today, but we'd need to be really sure.

I have never observed behavior to the contrary -- functions with no consumed tracked data never re-evaluate (unless the parent context is torn down and re-rendered -- which would be expected, ofc)

Can we move forward with this PR? <3

@NullVoxPopuli
Copy link
Sponsor Contributor

NullVoxPopuli commented May 28, 2023

I pushed up a rebase + some minor tweaks in #20464 -- thanks for getting this started @TechieQian !!! you're the best 🎉

wagenet added a commit that referenced this pull request Jun 7, 2023
[FEATURE] Create public import for uniqueId helper #20171
@wagenet
Copy link
Member

wagenet commented Jun 7, 2023

Closed by #20464.

@wagenet wagenet closed this Jun 7, 2023
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.

None yet

6 participants