Skip to content

Commit

Permalink
fix: remove auto inject
Browse files Browse the repository at this point in the history
BREAKING CHANGE: remove auto inject, need to use inject to add service to controllers, routes or components. See readme.
  • Loading branch information
knownasilya committed Sep 30, 2019
1 parent 8e2fe93 commit ad8cecf
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 122 deletions.
5 changes: 4 additions & 1 deletion .template-lintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

module.exports = {
extends: 'recommended'
extends: 'recommended',
rules: {
quotes: 'single'
}
};
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,16 @@ Compatibility
* Ember.js v3.4 or above
* Ember CLI v2.13 or above
* Node.js v8 or above
* Requires jQuery (see https://github.com/emberjs/ember-jquery)

## Usage

```sh
ember install ember-toastr
```

The toastr service is injected as `toast` into controllers, routes, and components,
so it can be used like so:

```js
this.toast.info('Hello there!');
```
> :warning: Version 2.0 will probably remove the automatic injection into controllers and components in favor of service injection, and your own automatic injection.
If you want to access it anywhere else, please inject it
You can now access the notifications service as `toast`.
You can inject it in routes, controllers or components using the following syntax:

```js
import Route from '@ember/routing/route';
Expand All @@ -37,19 +31,18 @@ export default Route.extend({
notifications: service('toast'),

test() {
// don't forget to use `get`, since injections are computed properties
let notifications = this.get('notifications');

notifications.info('text', 'title', options);
this.notifications.info('text', 'title', options);
}
});
```

> If using newer versions of Ember you can inject using the decorator syntax, see the Ember documentation for @ember/service#inject decorator.
You can also use `toast.clear()` and `toast.remove()` to
remove all toasts. For example:

```hbs
<button onclick={{action toast.clear}}>Clear</button>
<button {{on "click" this.toast.clear}}>Clear</button>
```

See the toastr.js [demo] for other possible uses, and the [toastr.js documentation]
Expand Down
12 changes: 0 additions & 12 deletions addon/initializers/toastr.js

This file was deleted.

42 changes: 0 additions & 42 deletions app/initializers/toastr.js

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"node": "8.* || >= 10.*"
},
"devDependencies": {
"@ember/jquery": "^0.6.1",
"@ember/optional-features": "^1.0.0",
"babel-eslint": "^10.0.3",
"broccoli-asset-rev": "^3.0.0",
Expand Down
52 changes: 0 additions & 52 deletions tests/.jshintrc

This file was deleted.

3 changes: 3 additions & 0 deletions tests/dummy/app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';

export default Controller.extend({
toast: service(),

actions: {
info(val) {
this.toast.info(val, val, { progressBar: false });
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/config/optional-features.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"jquery-integration": false
"jquery-integration": true
}
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,18 @@
resolved "https://registry.yarnpkg.com/@ember/edition-utils/-/edition-utils-1.1.1.tgz#d5732c3da593f202e6e1ac6dbee56a758242403f"
integrity sha512-GEhri78jdQp/xxPpM6z08KlB0wrHfnfrJ9dmQk7JeQ4XCiMzXsJci7yooQgg/IcTKCM/PxE/IkGCQAo80adMkw==

"@ember/jquery@^0.6.1":
version "0.6.1"
resolved "https://registry.yarnpkg.com/@ember/jquery/-/jquery-0.6.1.tgz#eef89ebc8d7b49bddc176f2a646746c8f5d93978"
integrity sha512-XMgfUYag97YOYLsC0Ys4/H6mHO2U2wra/92eVIug+5eYBloYSDhv2MY/iq/ocwXVSB2dQaphJx5pFXqdrjEzWQ==
dependencies:
broccoli-funnel "^2.0.2"
broccoli-merge-trees "^3.0.2"
ember-cli-babel "^7.7.3"
ember-cli-version-checker "^3.1.3"
jquery "^3.4.1"
resolve "^1.11.1"

"@ember/optional-features@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@ember/optional-features/-/optional-features-1.0.0.tgz#8e54ff37f4d9642212b45387f182cf7322aaaab9"
Expand Down

0 comments on commit ad8cecf

Please sign in to comment.