-
-
Notifications
You must be signed in to change notification settings - Fork 160
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
Deprecate EmberObject Usage? #287
Comments
@jherdman I've got a proof-of-concept branch with a working refactor (all tests green) if you want to check it out: https://github.com/jfdnc/ember-metrics/tree/refactor/remove-ember-object One of the things that I don't feel entirely sure about, just because I haven't used this API before, is using Also included in the linked branch is an in-place refactor/cleanup of the Any feedback is welcome, would love to be of help here if this seems like a plausible path forward. |
Some high level thoughts as I'm chewing on this still:
Everything looks solid. Here are my next steps:
|
Happy to, yep!
I kept My guess is that the most common bits of Given those things, it might be the most responsible thing to do a deprecation release first before removing the underlying |
I guess |
Another minor note in thinking about deprecations moving forward, the |
@jfdnc the Metrics service refactor has been merged. Are you interested in getting your GA refactor in too? |
@jfdnc I had another thought this morning I wanted to bounce off of you. A while back I investigated https://github.com/DavidWells/analytics as a possible underpinning for this library. One of the things I considered a blocker back then was that there is no way to remove an injected third party script for analytics from the DOM (DavidWells/analytics#78). As far as I can tell the author's response is correct — just because we removed the script from the DOM doesn't mean that the code will stop running. Really we only do it here for testing. This is today's shower thought: does it even make sense to continue supporting script tag removal? |
It may make more sense to isolate the removal to just the testing environment. Given that those scripts are registering code that isn't torn down by removing the Either way, the I do think it is still a good idea to expose some method in the various adapters to hook into service teardown, since any given application might want to handle concerns at that time, especially if they are running a custom local adapter. One of the things I mentioned previously was maybe leveraging Current service initiates willDestroy() {
for (let adapter of this._adapters) {
adapter.destroy();
}
} The service's willDestroy() {
for (let adapter of this._adapters) {
adapter.willDestroy(); // or adapter.onTeardown()
}
} and the behavior from a consuming app will remain the same. Another related thought here is that the adapters are targeting those scripts with a CSS |
IMHO plain JavaScript is better, i.e.
Another problem we don't need to worry about if we just don't do it 😉 You're right though: if we're going to keep ripping the script tags out we need to do it safely. It's a bit challenging given the heterogeneous nature of script insertion — both on our end, and of the vendor themselves. |
One way to attach markers for script removal would be like import { guidFor } from '@ember/object/internals';
...
class MyCoolAdapter extends BaseAdapter {
constructor() {
// could technically just use component name like `data-ember-metrics-my-cool-adapter`
// but generating it always ensures a unique target for removal per the adapter
this.dataAttrForScript = `data-ember-metrics-${guidFor(this)}`
}
_injectScript() {
// this looks different per the adapter
// but generally we can find where `createElement` is called
// and then add in `element.setAttribute(this.dataAttrForScript, '')`
// so the element looks like `<script data-ember-metrics-0fxbaetc src="...`
}
willDestroy() {
// could call here by default
// or just expose `dataAttrForScript` (or whatever name) if the consumer wants to handle it
removeFromDOM(`script[${this.dataAttrForScript}]`)
}
} |
@jfdnc let's just decorate the script tags with |
I just saw the talk here. I probably shot to quick a PR about it: #331 It seems the solution implemented in the PR was already investigated by @jfdnc. |
@GreatWizard PR looking solid! I don't mind deferring my branch for PR, looks like you took a similar approach (I like the |
I'll stop dragging my buns on a deprecation PR so that this can move forward. My apologies to you both. |
OK, the initial deprecation PR is merged. The next step is to deprecate the |
Each adapter inherits for EmberObject. Is it possible for us to just write native classes?
The text was updated successfully, but these errors were encountered: