You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Varying service syntaxes can result in separate services rather than one shared service. This came up in an app where an addon component invoked a service from the addon in one way and the app invoked the service in another way. It doesn't seem like the app should need to know how the addon service is invoked in order to function properly.
The various invocations I tested were:
@service() - relying on the variable name matching the service name
It creates a service and then 4 components that use the service with the syntaxes listed above. It creates table cells containing buttons to interact with the service and the value coming from the service for each component. A console.log is also placed in the service's constructor to show how many times it is being instantiated.
😕 Actual Behavior
Separate services are created by varying syntaxes. The gif below shows sample usage of the reproduction app.
🤔 Expected Behavior
Only one service is created regardless of the syntax used. In the gif above that would result in all of the right side values always being synced.
🌍 Environment
Ember: - 3.18.0 (in the repro app), 3.26.2 in the app where I noticed this
Node.js/npm: - 6.14.10
OS: - osx
Browser: - chrome
The text was updated successfully, but these errors were encountered:
So generalizing, the pattern for looking up something from a foreign package is:
this.owner.lookup(`${packageName}@{type}:${name}`);
this.owner.lookup(`{type}:${packageName}@${name}`);
how does that translate into the service invocation?
Does @service(${packageName}@${name}) translate into something like this.owner.lookup(service:${packageName}@${name})?
If this is the case, what are best practices as either an addon creator or in the consuming app? Currently, I have a situation where an addon service uses the #2 syntax from the first message and the app uses the #3 syntax, resulting in separate service instances.
🐞 Describe the Bug
Varying service syntaxes can result in separate services rather than one shared service. This came up in an app where an addon component invoked a service from the addon in one way and the app invoked the service in another way. It doesn't seem like the app should need to know how the addon service is invoked in order to function properly.
The various invocations I tested were:
1/2 create one shared instance of a service and 3/4 create a separate shared instance of a service.
🔬 Minimal Reproduction
There's a minimal reproduction of this at https://github.com/tcwood/ember-service-repro
It creates a service and then 4 components that use the service with the syntaxes listed above. It creates table cells containing buttons to interact with the service and the value coming from the service for each component. A console.log is also placed in the service's constructor to show how many times it is being instantiated.
😕 Actual Behavior
Separate services are created by varying syntaxes. The gif below shows sample usage of the reproduction app.
🤔 Expected Behavior
Only one service is created regardless of the syntax used. In the gif above that would result in all of the right side values always being synced.
🌍 Environment
The text was updated successfully, but these errors were encountered: