-
Notifications
You must be signed in to change notification settings - Fork 12
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
Encode Behavior in Link Primitive + Building Blocks #578
Comments
1st AttemptHere is the idea for my first attempt, which is basically shoving symmetry in creating links as well as in attaching them to elements (after you created them and send them off as primitive). Giving link creators the ability to store all intentions and tools for implementors to respect them. I'll explain at some highlights of described API changes below - this is a way to give clear opinion on how to use Creating Links
Positional args: required (target) Same way to create links in declarative and imperative form 😎
Opening BehaviorWhoever is responsible for attaching the link to the element is in charge of the link stacks onto the history (using
So an implementer is safe to respect the intention for opening. AttachingAnd the attachers:
Use the latter and you should be good. Use the former, if you take care of invoking business already and want to treat links, too:
The ProblemI'm really happy about the public API expressed above. The main problem is in how it is processed under the hood. Mainly I see three ways of doing so:
Routes expose a different public API as links. They have all the getters in which state they are in to be used for styling and also control the history behavior (transition vs replace). Whereas just URLs do not know this. Solution 1Would be to explcitely differentiate between routes know to the app and just URLs in terms of API surface: Dealing with two links is already not ideal as the current Solution 2When creating a link, we can assign it a handler. A
That would enable for the Solution 3Taken from making illegal states unrepresentable is to some extend yield different APIs in relation to the identified target. While this works quite nice for the shown Summary
|
The Problem
ember-link
provides a primitive to pass around. It's a bit of fuzzy what it is exactly. It can be seen as just a DTO and on the other hand provides operations how to deal with the link itself (such astransitionTo()
andreplaceWith()
methods).Using them together is fine, when the owner of the primitive is also in control of how a link get's attached to the UI. This no longer works when the two split (ie. when the primitive is passed around).
A Solution
In order to make it work, this needs handling on two sides of the problem:
A sample for (1) - making up some possibly imaginery code (as I don't have the full and correct API in my head):
Onto the second part of the solution (2). Let's say, this we received our link in a component as
@link
argument:There are two additions here:
@link.open
- which would be used to either calltransitionTo()
orreplaceWith()
on the link{{link-attributes}}
- which would put all attributes onto the element as needed (e.g.target="_blank"
to open in a new window)This is partially the idea from #333 - yet a little bit more exhaustive. First, it is good to have these multiple pieces as building blocks (see below on thiird party implementors). There maybe can also be just one modifier that handles all of the above
@link
related markup in one place.As implementor, using that interface would give me the chill, that I attached the link properly to my markup.
For third party implementors, the exhaustive building blocks might be more suitable. See here: https://github.com/gossi/ember-command/blob/9101687488c9c20e4c7e9510632f44c38cd88a1f/addon/components/commander/index.hbs
The text was updated successfully, but these errors were encountered: