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
It's best practice to use flash messages sparingly, only when you need to notify the user of something. If you're sending too many messages, and need a way for your users to clear all messages from screen, you can use this method:
268
258
269
259
```javascript
270
-
import { get } from'@ember/object';
271
-
272
-
get(this, 'flashMessages').clearMessages();
260
+
this.flashMessages.clearMessages();
273
261
```
274
262
275
263
### Returning flash object
276
264
The flash message service is designed to be Fluent, allowing you to chain methods on the service easily. The service should handle most cases but if you want to access the flash object directly, you can use the `getFlashObject` method:
277
265
278
266
```javascript
279
-
import { get } from'@ember/object';
280
-
281
-
constflashObject=get(this, 'flashMessages').add({
267
+
constflashObject=this.flashMessages.add({
282
268
message:'hola',
283
269
type:'foo'
284
270
}).getFlashObject();
@@ -321,7 +307,7 @@ See the [options](#custom-messages-api) section for information about flash mess
This option lets you specify exactly what types you need, which means in the above example, you can do `Ember.get('flashMessages').{alpaca,notice,foobar}`.
310
+
This option lets you specify exactly what types you need, which means in the above example, you can do `this.flashMessages.{alpaca,notice,foobar}`.
325
311
326
312
-`preventDuplicates?: boolean`
327
313
@@ -334,23 +320,23 @@ Then, to display somewhere in your app, add this to your template:
334
320
335
321
```handlebars
336
322
{{#each flashMessages.queue as |flash|}}
337
-
{{flash-message flash=flash}}
323
+
<FlashMessage @flash={{flash}} />
338
324
{{/each}}
339
325
```
340
326
341
327
It also accepts your own template:
342
328
343
329
```handlebars
344
330
{{#each flashMessages.queue as |flash|}}
345
-
{{#flash-message flash=flash as |component flash|}}
331
+
<FlashMessage @flash={{flash}} as |component flash|>
@@ -359,12 +345,12 @@ The `close` action is always passed to the component whether it is used or not.
359
345
360
346
When using a custom `close` action, you will want to set `destroyOnClick=false` to override the default (`destroyOnClick=true`). You could do this globally in `flashMessageDefaults`.
361
347
362
-
```
348
+
```handlebars
363
349
{{#each flashMessages.queue as |flash|}}
364
-
{{#flash-message flash=flash as |component flash close|}}
350
+
<FlashMessage @flash={{flash}} as |component flash close|>
@@ -406,7 +392,7 @@ If the provided component isn't to your liking, you can easily create your own.
406
392
407
393
```handlebars
408
394
{{#each flashMessages.queue as |flash|}}
409
-
{{custom-component flash=flash}}
395
+
<CustomComponent @flash={{flash}} />
410
396
{{/each}}
411
397
```
412
398
@@ -419,56 +405,83 @@ $ ember generate ember-cli-flash
419
405
420
406
This also adds the helper to `tests/test-helper.js`. You won't actually need to import this into your tests, but it's good to know what the blueprint does. Basically, the helper overrides the `_setInitialState` method so that the flash messages behave intuitively in a testing environment.
421
407
408
+
Some example tests below, based on qunit.
409
+
422
410
An example acceptance test:
423
411
424
412
```javascript
425
-
// tests/acceptance/foo-test.js
413
+
// tests/acceptance/foo-page-test.js
414
+
415
+
import { module, test } from'qunit'
416
+
import { setupApplicationTest } from'ember-qunit'
417
+
import { click, visit } from'@ember/test-helpers'
418
+
419
+
module('Application | Component | foo-page', function (hooks) {
420
+
setupApplicationTest(hooks)
426
421
427
-
test('flash message is rendered', function(assert) {
428
-
assert.expect(1);
429
-
visit('/');
422
+
test('flash message is rendered', asyncfunction(assert) {
test('it does the thing it should do', function(assert) {
477
+
constsubject=this.owner.lookup('route:foo')
478
+
...
479
+
})
467
480
});
468
481
```
469
482
470
483
## Styling
471
-
This addon is minimal and does not currently ship with a stylesheet. You can style flash messages by targeting the appropriate alert class (Foundation or Bootstrap) in your CSS.
484
+
This addon is minimal and does not currently ship with a stylesheet. You can style flash messages by targeting the appropriate alert classes in your CSS.
472
485
473
486
## License
474
487
[MIT](LICENSE.md)
@@ -507,4 +520,4 @@ We're grateful to these wonderful contributors who've contributed to `ember-cli-
0 commit comments