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

Link component hook #230

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions text/0000-Link-Component-Invoke-Hook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
- Start Date: 2017-06-12
- RFC PR:
- Ember Issue:

# Summary

Right now there's no public API surrounding the LinkComponent's `_invoke` method. Adding this would allow for addons and applications to extend the LinkComponent and easily add logic gates around the `_invoke` as well as allow for added functionality prior to the transition.

# Motivation

- Analytics and click tracking
- Open routes in modals based on environment

# Detailed design

Right now the `init` directly hooks the user-defined event type to fire the `_invoke` which is private. `_invoke` then directly works on the transition to the new route.

A new public method `eventAction` will be bound during `init` instead of the `_invoke`. `eventAction` simply calls `_invoke`.

Extended components can now override `eventAction`, perform additional logic such as metrics/click-tracking and also logically gate a call to `_super` which would continue execution to transition the route as normal.

# How We Teach This

Recommend making this change as unobtrusive as possible and silently adding the new method to the documentation. Several very common addons will likely benefit from this change and can likely move off of some private overrides currently being used.

Most Ember consumers will benefit from this change via addon updates, rather than direct usage.

# Drawbacks

Adding additional features is a difficult sell as LinkComponent is likely set to be reworked into a more modular approach.

# Alternatives

Also considered adding a `shouldInvoke` method that returns a boolean and then having `_invoke` call `shouldInvoke` at the head of the function. `_invoke` would then NOOP if `shouldInvoke` returns `false`.

This approach is less clear as a means to add additional pre-invoke logic.

While Ember does use `should` prefixes to a certain extent, it is far from a common naming scheme currently.

# Unresolved questions

Is it worth making this change, albeit a very small one, in light of current mentalities to break LinkComponent down into a collection of more specific micro-components?