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 to public APIs for head/tail #54

Merged

Conversation

@mixonic
Copy link
Contributor

@mixonic mixonic commented Jun 3, 2016

In the template for ember-wormhole, use helpers that register an element to the parent wormhole component. The wormhole component can then use those elements to move to the target. This lessens the private APIs used by wormhole, but still uses private APIs to access the DOM or Fastboot SimpleDOM based on where the code is running. This could use all private API if we made SimpleDOM a dependency, but that would just inflate the JS payload with little benefit.

This unblocks Fastboot rendering. It will also mean dropping support for Ember versions before 1.13. See #47 for discussion.

TODO:

  • Remove support for Ember pre-1.13
  • Check for isDestroyed in the afterRender callback.
  • Document Fastboot status
  • Document/test passing a bare element to destinationElement
  • Move SimpleDOM/DOM compat tooling to a util module
  • Document subclassing of the wormhole component class skipping this, but after merge and release I will open an issue/PR on the x-favicon repo
this._didInsert = true;
run.schedule('afterRender', () => {
// read the values from the ember-wormhole-placeholder helpers
this._firstNode = this.get('registry.head');
Copy link
Contributor

@krisselden krisselden Jun 4, 2016

Choose a reason for hiding this comment

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

what is the registry thing solving?

Loading

Copy link
Contributor

@krisselden krisselden Jun 4, 2016

Choose a reason for hiding this comment

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

Nevermind, it is because this is before children are rendered, is there no hook on didCreateElement? I thought there was, anyway, I don't think this should be generic and use slots. Not only because this isn't very JIT friendly but because it is confusing like it is some general feature.

Loading

Copy link
Contributor Author

@mixonic mixonic Jun 4, 2016

Choose a reason for hiding this comment

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

didInsertElement is not fired for Fastboot. We kind of want a "fire all hooks I know what I'm doing" mode for Fastboot rendering. Doesn't seem likely. So instead we emulate the timing of didInsertElement using the hooks that do fire.

Regarding slots you suggest this should use an array instead? Would pre-defining the shape also be sufficient?

  init() {
    this._super(...arguments);
    this.wormholeNodeRegistry = { head: null, tail: null };
  },

Loading

Copy link
Contributor Author

@mixonic mixonic Jun 4, 2016

Choose a reason for hiding this comment

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

cool, refactored away from this.

Loading

@mixonic mixonic force-pushed the fastboot-without-private-apis branch from ce9c73f to 2fb4b96 Jun 4, 2016
@mixonic
Copy link
Contributor Author

@mixonic mixonic commented Jun 4, 2016

Another pass at the implementation here for review. @krisselden I did not refactor destinationElement away from being a CP. Can we punt that and the refactor away from observers to another pass?

The ember-try config here is updated, perhaps travis needs a cache flush.

I'll flesh out the docs changes later today.

Loading

@chrislopresto
Copy link
Contributor

@chrislopresto chrislopresto commented Jun 4, 2016

@mixonic I cleared the Travis cache and rekicked the build.

Loading

@chrislopresto
Copy link
Contributor

@chrislopresto chrislopresto commented Jun 4, 2016

@mixonic Ah, the travis.yml needs to be updated.

Loading

@mixonic mixonic force-pushed the fastboot-without-private-apis branch 2 times, most recently from 79d484d to 0f156ac Jun 6, 2016
@mixonic
Copy link
Contributor Author

@mixonic mixonic commented Jun 6, 2016

This is pretty wrapped up- @bantic can you please confirm with your fastboot demo app that this PR functions correctly?

I'm actually quite curious what will happen upon initial re-render of the page. The idea for fastboot users might be that the nodes inside that part of the page are destroyed and re-rendered. But we should know what is happening for sure.

Loading

@bantic
Copy link
Contributor

@bantic bantic commented Jun 7, 2016

@mixonic Yeah, this works great with the demo app I was testing.

Loading

@lukemelia
Copy link
Contributor

@lukemelia lukemelia commented Jun 7, 2016

Nice work on this, all. Thanks for driving the implementation@mixonic! I'm +1 on merging and releasing 0.4.0 assuming @chrislopresto is as well.

Loading

@bantic
Copy link
Contributor

@bantic bantic commented Jun 7, 2016

Loading

@@ -0,0 +1,3 @@
{{ember-wormhole-placeholder (unbound _firstNode) ~}}
{{yield ~}}
{{ember-wormhole-placeholder (unbound _lastNode) ~}}
Copy link
Contributor

@chrislopresto chrislopresto Jun 8, 2016

Choose a reason for hiding this comment

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

@mixonic With the disclaimer that I haven't fastboot-ed, can you explain how this differs from:

{{unbound _firstNode ~}}
{{yield ~}}
{{unbound _lastNode ~}}

If these approaches are functionally equivalent, we could ditch the placeholder helper (and rename _firstNode and _lastNode to something more expressive).

Loading

@bantic bantic force-pushed the fastboot-without-private-apis branch from 2af706c to b01f5e6 Jun 8, 2016
Generate placeholder nodes in the `ember-wormhole` component and use the
`unbound` helper in its template to place those nodes before and after
userland yielded content. The wormhole component then uses these
placeholders to move its contents to the target element.

Also adds public documentation that `destinationElement` can be passed
directly instead of `to` with a string element ID.

 * [breaking] Raise minimum required version to 1.13
 * Note fastboot compat in README.md
 * Document destinationElement
@bantic bantic force-pushed the fastboot-without-private-apis branch from b01f5e6 to 36ee4fd Jun 8, 2016
@chrislopresto chrislopresto merged commit 18182d5 into yapplabs:master Jun 8, 2016
1 check passed
Loading
@chrislopresto
Copy link
Contributor

@chrislopresto chrislopresto commented Jun 8, 2016

Onward!

Loading

@mixonic mixonic deleted the fastboot-without-private-apis branch Jun 8, 2016
@bantic bantic mentioned this pull request Jun 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants