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

[REFACTOR] Refactors while integrating with Ember #993

Merged
merged 26 commits into from
Dec 18, 2019

Conversation

pzuraq
Copy link
Member

@pzuraq pzuraq commented Nov 16, 2019

Changelog

  • Overall updates

    • Added @glimmer/env to the build, usable from Ember as well.
    • Converted to native symbol, with a simple polyfill
  • Updates to the Runtime builders (AotRuntime(),JitRuntime())

    • Can now accept an options hash as the first argument containing
      either the document or append/update operations.
  • Updates to Environment

    • Removed DefaultEnvironment
    • Simplified environment inheritance tree, flattened down to one class
    • Added willDestroy to environment for WILL_DROP (legacy sync drops)
  • Updates to the RuntimeEnvironmentDelegate:

    • Rename to EnvironmentDelegate
    • Added isInteractive, equivalent of Ember's usage (should update?)
    • Added extra field, which is a generic type for the Environment. This
      allows the embedding environment to pass any extra values they need.
    • Removed the iterables API, key for methods are now statically
      generated and entirely a concern of the IteratorImpl
    • Added toIterator, which allows the delegate to provide an
      IteratorDelegate for a given value. To keep things simpler and
      more performant, this is not yet a true browser delegate. This way,
      it matches the API of the (now internal) IterationItem.
      • Note for future: key and memo names are fairly confusing,
        maybe memo -> index?
    • Added getPath/setPath to allow Ember to provide a getter/setter
      implementation, allowing for PropertyReference to delegate property access,
      along with keyFor in iterators.
    • Added setTemplatePathDebugContext/getTemplatePathDebugContext. These are
      used to add debug context for paths in templates (e.g. {{this.foo}} or
      {{my-helper}}) to the DebugRenderTree in Ember. Eventually they should
      be removed, when the DebugRenderTree has been pulled upstream into Glimmer.
  • Updates to IterableImpl

    • Added the IteratorDelegate interface (could maybe use a better
      name). This is the minimal API to let Ember provide all the
      different types of iterators it needs to (in particular,
      EmberArray, objects with forEach, and {{each-in}} iterators).
    • No more native iterables - we don't support Symbol yet, plus it's
      fairly redundant with IteratorDelegate.
    • Very simple IteratorWrapper class instead, which adds the key
      to the final iteration item internally. No more need to expose
      keyFor concerns to Ember, except getPath.
  • Updates to @glimmer/runtime

    • Added WILL_DROP to destroyables, and willDestroy to component managers
  • Updates to @glimmer/reference

    • Removed MapReference
    • Removed UpdatableReference, replaced with UpdatableRootReference and
      IterationItemReference
    • Refactored the majority of references around two base assumptions.
      • Generally, references should refer to values in the template
      • There are fundamentally two kinds of references in the template: Roots
        and properties. Roots are unique, there are a few different types.
        Properties are almost all the same.
    • All template references now receive the env, which allows them to delegate
      access, and setup debug context.
  • Updates to @glimmer/validator

    • Added the autotracking transaction from Ember, along with an API for setting
      it up based on the embedding environment.
    • Simplified the meta system, now it's just a few WeakMaps.
    • Added DEBUG assertions against incorrect usage of tags, for instance
      updating a tag with a more recent tag in a way that wouldn't bust the cache.

- Updates to the Runtime builds (`AotRuntime()`,`JitRuntime()`)
  - Can now accept an options hash as the first argument containing
    either the document or append/update operations.
- Updates to the RuntimeEnvironmentDelegate:
  - Removed the `iterables` API, key for methods are now statically
    generated and entirely a concern of the IteratorImpl
  - Added `toIterator`, which allows the delegate to provide an
    `IteratorDelegate` for a given value. To keep things simpler and
    more performant, this is not yet a true browser delegate. This way,
    it matches the API of the (now internal) `IterationItem`.
      - Note for future: `key` and `memo` names are fairly confusing,
        maybe `memo` -> `index`?
  - Added `getPath` to allow Ember to provide a getter implementation,
    allowing `keyFor` to be fully pluggable. This will probably also be
    necessary for `RootReference` if we want to use the upstream version
    provided by Glimmer now, since it needs to use `get` to autotrack
    correctly.
- Updates to `IterableImpl`
  - Added the `IteratorDelegate` interface (could maybe use a better
    name). This is the minimal API to let Ember provide all the
    different types of iterators it needs to (in particular,
    `EmberArray`, objects with `forEach`, and `{{each-in}}` iterators).
  - No more native iterables - we don't support `Symbol` yet, plus it's
    fairly redundant with `IteratorDelegate`.
  - Very simple `IteratorWrapper` class instead, which adds the key
    to the final iteration item internally. No more need to expose
    `keyFor` concerns to Ember, except `getPath`.
Chris Garrett added 7 commits December 13, 2019 12:13
This allows local tests to use DEBUG and test against errors and
assertions. This commit also fixes a few assertions, some of which could
not work for one reason or another, and some of which needed tweaking.

In particular, `@glimmer/validator` need a tweak in DEBUG mode. Our
current assumption is that by the first time you call `value` on a tag
in a render, that tag's value should truly be locked down, and you
should not be able to change it without a call to `dirty()` somewhere.
This allows us to cache the value. We also use a trick to allow us to
compute the value _once_ during `validate()` in production builds - We
know the global $REVISION cannot possibly be less than the value of the
tag, so we return it directly.

However, this does mean that it _is_ valid to update the value of a tag
between a false `validate()` and `value()`, and this is expected, as we
have a number of cases where we do this. This commit introduces an
assertion that throws if you attempt to update a tag to a more recent
value after it has been locked in, and in DEBUG it prevents caching
while revalidating in order to allow that brief period between a false
`validate()` and a `value()` to not trigger this assertion.
package.json Show resolved Hide resolved
ember-cli-build.js Outdated Show resolved Hide resolved
@pzuraq pzuraq changed the title [WIP][REFACTOR] Refactors while integrating with Ember [REFACTOR] Refactors while integrating with Ember Dec 17, 2019
@pzuraq pzuraq marked this pull request as ready for review December 17, 2019 03:51

# v0.45.0

* `@glimmer/runtime`
Copy link
Member

Choose a reason for hiding this comment

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

Just a note to remind myself to copy this content into the changelog when we land / release this.

Comment on lines 86 to 88
let glimmerEnv = funnel('node_modules/@glimmer/env', {
include: ['dist/amd/es5/*.{js,map}'],
});
Copy link
Member

Choose a reason for hiding this comment

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

Can you check if we can remove this?

super(env);

if (DEBUG) {
let name = debugName || fn.name;
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit unfortunate, we should try to figure out how we can thread through the invoked helper name here.

Seems totally fine to followup with this though...

packages/@glimmer/reference/lib/template.ts Show resolved Hide resolved
compute() {
this.computeTag = track(() => {
this.computeValue = this.fn(this.args);
}, DEBUG && `${this.env.getTemplatePathDebugContext(this)}`);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}, DEBUG && `${this.env.getTemplatePathDebugContext(this)}`);
}, DEBUG && this.env.getTemplatePathDebugContext(this));

): JitRuntimeContext {
let env = new RuntimeEnvironment(document, new RuntimeEnvironmentDelegateImpl(delegate));
resolver: RuntimeResolverDelegate<R> = {},
delegate: EnvironmentDelegate<E> = {}
Copy link
Member

Choose a reason for hiding this comment

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

I think ideally we should try to make it so that the only thing in the system that is aware of the delegate setup that we are using is the environment. I don't particularly think that will make much difference here at the moment, but it does isolate unrelated parts of the system (like this one) from other future changes that we might make to the delegate.

tldr; lets pass the environment here instead of the delegate, but seems fine to do in a follow up...

packages/@glimmer/runtime/lib/lifetime.ts Show resolved Hide resolved
packages/@glimmer/runtime/lib/lifetime.ts Show resolved Hide resolved
@@ -35,6 +38,10 @@ export function associateDestructor(parent: object, child: Drop): void {
associated.add(child);
}

export function peekAssociated(parent: object): Option<Set<Drop>> {
return LINKED.get(parent) || null;
Copy link
Member

Choose a reason for hiding this comment

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

:trollface:

  return LINKED_IN.get(parent) || null;

packages/@glimmer/validator/lib/utils.ts Show resolved Hide resolved
@rwjblue rwjblue merged commit ee0b970 into master Dec 18, 2019
@rwjblue rwjblue deleted the refactor/ember-integration branch December 18, 2019 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants