-
Notifications
You must be signed in to change notification settings - Fork 0
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
Drop prefix from canonical property #5
base: master
Are you sure you want to change the base?
Conversation
I think
This is a minor benefit given that users should not need to access the property directly. I agree that it would be nice, but I would argue for |
David beat me to the punch. |
As @gabejohnson mentioned we want to avoid name clashes. Plus forcing to use string literal seems to help Google Closure compiler to handle it right (was mentioned here fantasyland/static-land#45 (comment))
In fact we may introduce other properties, see #3 for example. |
I don't see how it is more descriptive? Fantasy Land is just the name of the specification? It seems more descriptive to call the canonical property
What libraries have a property called To me, the most important thing is to drop the slash. I still think |
I don't consider |
Yes, I agree with that. You're definitely right that the name isn't arbitrary in that it very specifically mentions which specification it is part of. But, my point was more that the specification name Fantasy Land itself is arbitrary. The specification might as well have been called Lambda Land or Fantasy Forest. It doesn't say anything about what the specification or what the method is. But, a name like
I hadn't seen that. Maybe this approach #2 (comment) would avoid that extra complexity? |
True, but it seems to me a reasonable way to virtually eliminate the possibility of accidental collisions. Also, a web search for |
I don't know of any, but I can imagine some library like JQuery using it as a flag on an object representing a Also, if we're making a proposal to use |
To me just |
Also, not to argue for keeping |
I can see what you mean. The word isn't actually very descriptive. What about
I actually don't think that example is a problem at all given the new design. I think we should consider how the new spec design changes the "name clash problem". Back when the prefix originally was introduced the spec used a lot of very popular names like
However, the new spec only uses a single property name. Let's say that name was
What I'm trying to say is that we shouldn't worry about name clashes due to reasons that were only relevant in the past. A name like |
Wasn't the original idea to reduce the amount of code? 😉 |
What do you all think about using an ES6 Symbol instead? It could live as a standalone npm package that people just install & import. Something like:
Inspiration: https://github.com/benlesh/symbol-observable for observables You would never have to worry about accidental name clashes at all this way. You could also alias it to |
I'm opposed to this option. It would increase the complexity of building and distributing ADT libraries for a negligible gain. A string is the pragmatic option. That's my view, at least. ;) |
Symbols are still relatively new, which causes two kinds of issues:
Although I have almost zero experience with Symbols, and can't give examples of any particular issues. To me, this just looks like complex and new technology, and using it seems like a risk, especially for a glue layer that supposed to connect many libraries. On the other hand, Symbols seem like a solution designed specifically for our problem and built-in into the language. This seems like a modern and idiomatic solution that any serious project should use. Perhaps if we adopt Symbols we may attract more developers. That are my thoughts, but as I say I don't really consider myself an expert in this area. |
From what I can tell from this discussion there is a broad agreement for moving away from the But there has been a few different suggestions about what the new property name should be. I'd like to update the PR to the most popular option. Please react to this comment with your preference and I'll update the PR accordingly afterward.
|
Just to throw my hat into the ring, check out: // Using `Symbol.for` to avoid forcing unwanted dependencies on everyone
const value = { [Symbol.for('fantasy-land')]: TypeRef, data: { ... } } or, to make your own code more concise: // my-internals.js
export const typeref = Symbol.for('fantasy-land')
// my-app.js
import { canonical } from './my-internals'
const value = { [typeref]: TypeRef, data: { ... } } It's getting kind of rare to encounter a scenario that doesn't support symbols. In my mind, lack of support for symbols should not preclude their use in a specification, but rather be backed by a suggestion to use some kind of namespace-equivalent polyfill in their absence. One thing you also lose in not using symbols is that JSON serialization will pick up the extended type reference as a subtree. Probably easily mitigated by simply implementing |
This PR renames the canonical property from
fantasy-land/canonical
to justcanonical
.As I mentioned in fantasyland#286 I think the prefix with a slash made more sense when there were many prefixed methods. By design, there is only a single canonical method. Having a "directory"-like prefix that is only ever going to have a single child seems a bit odd to me. It seems sufficient to just pick a name that is uncommon enough to no cause collisions. As far as I can tell
canonical
in itself does that job just fine.Benefits:
thing.canonical
instead ofthing["fantasy-land/canonical"]
.fantasy-land/canonical
gives the misleading impression that there are several functions behind the prefix (like there was previously).