Skip to content
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

Modernise Service embedded + accept a generic type parameter #149

Merged
merged 6 commits into from
Oct 19, 2021

Conversation

MrChocolatine
Copy link
Member

@MrChocolatine MrChocolatine commented Oct 15, 2021

Documentation

Add a section about TypeScript support (#149)

Features

Allow to pass type of embedded options to Service embedded (#149)

The Service embedded now accepts a generic type parameter to improve the accuracy of what it can return.

import Component from '@glimmer/component';
import { inject as service } from '@ember/service';

import type EmbeddedService from 'ember-cli-embedded/services/embedded';

export default class MyComponent extends Component {
  @service
  declare embedded: EmbeddedService<{ one: string, two?: string }>;

  get one() { // Return type inferred: `string | undefined`
    return this.embedded.get('one');
  }

  get two() {
    // TypeScript returns an error as `twoo` is not a recognised key
    return this.embedded.get('twoo');
  }
}

Refactor

Update Service embedded to native JS class (#149)

Tests

Make tests of Service embedded stricter (#149)

Prefer assert.strictEqual() over assert.equal().

@MrChocolatine MrChocolatine changed the title modernise service embedded Modernise Service embedded + accept a generic type parameter Oct 15, 2021
1. Remove key `isServiceFactory`

This key does not seem required anymore. Without it the tests still pass
without any warning and a consuming application also does not get any
warning when using this add-on.

This key seems to be a relic from Ember.js <= v2, where it was required
when a Servive was extending `Ember.ObjectProxy` instead of `Service`.

See:
- DockYard/ember-cart#21
- https://github.com/emberjs/ember.js/search?q=isServiceFactory&type=issues

2. Condense export of the Service

Using a `const` was already not necessary before, we could have chained
`reopenClass()` right after the `ObjectProxy.extend()`.
And declare the Service in the registry of Services.
@MrChocolatine MrChocolatine force-pushed the modernise-service-embedded branch 2 times, most recently from 9392489 to 4bc2287 Compare October 18, 2021 17:58
@MrChocolatine MrChocolatine marked this pull request as ready for review October 19, 2021 10:26
@MrChocolatine MrChocolatine requested a review from a team as a code owner October 19, 2021 10:26
@MrChocolatine MrChocolatine merged commit 331e543 into master Oct 19, 2021
@MrChocolatine MrChocolatine deleted the modernise-service-embedded branch October 19, 2021 12:34
@MrChocolatine MrChocolatine mentioned this pull request Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants