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

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?

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.

Copy link
Contributor Author

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 };
  },

Copy link
Contributor Author

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.

@mixonic mixonic force-pushed the fastboot-without-private-apis branch from ce9c73f to 2fb4b96 Compare June 4, 2016 14:04
@mixonic
Copy link
Contributor Author

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.

@chrislopresto
Copy link
Contributor

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

@chrislopresto
Copy link
Contributor

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

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

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.

@bantic
Copy link
Contributor

bantic commented Jun 7, 2016

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

@lukemelia
Copy link
Contributor

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.

@bantic
Copy link
Contributor

bantic commented Jun 7, 2016

Pushed the demo app to Heroku: https://ember-wormhole-fastboot-demo.herokuapp.com/

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

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).

@bantic bantic force-pushed the fastboot-without-private-apis branch from 2af706c to b01f5e6 Compare June 8, 2016 15:57
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 Compare June 8, 2016 16:03
@chrislopresto chrislopresto merged commit 18182d5 into yapplabs:master Jun 8, 2016
@chrislopresto
Copy link
Contributor

Onward!

@mixonic mixonic deleted the fastboot-without-private-apis branch June 8, 2016 16:30
@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
Development

Successfully merging this pull request may close these issues.

5 participants