Skip to content
This repository has been archived by the owner on Nov 6, 2019. It is now read-only.

Make Phosphor safe to load on the page more than once #443

Open
sccolbert opened this issue Oct 19, 2019 · 4 comments
Open

Make Phosphor safe to load on the page more than once #443

sccolbert opened this issue Oct 19, 2019 · 4 comments

Comments

@sccolbert
Copy link
Member

sccolbert commented Oct 19, 2019

Forcing Phosphor to be a singleton on the page is "not nice" for projects which consume Phosphor. It means new functionality in Phosphor is not available for the users of those downstream projects until those projects update their dependencies. For Phosphor 2.0 (which should hopefully be the last major version of Phosphor) I think we can do better.

One idea that I have is to leverage Symbol.for('@phosphor/[email protected]') and tag the Widget prototype with that Symbol for each minor release. Since the Symbol is guaranteed to be global on the page, it would let duplicate prototypes function just fine, because we could guarantee they have the needed API. Instead of using the instanceof operator, we could have some convenience functions for checking the presence of the symbols.

This idea may have holes, but it's a good starting point I think.

CC @afshin @blink1073 @jasongrout

@jasongrout
Copy link
Member

So this parallels the ideas behind tokens, but now uses Symbols for their global nature (and since they are available now)?

@blink1073
Copy link
Contributor

We had also discussed using Symbols for tokens themselves so you could have multiple providers.

@jasongrout
Copy link
Member

We had also discussed using Symbols for tokens themselves so you could have multiple providers.

That's right. Versioned interfaces.

@sccolbert
Copy link
Member Author

So this parallels the ideas behind tokens, but now uses Symbols for their global nature (and since they are available now)?

Somewhat. I think it's more subtle than first glance. TypeScript may still not like it, for example.

We had also discussed using Symbols for tokens themselves so you could have multiple providers.

Yep.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants