Skip to content

Commit ea07232

Browse files
committedAug 11, 2015
Tests passing in 1.13.3
1 parent c575557 commit ea07232

21 files changed

+305
-402
lines changed
 

‎Brocfile.js

-21
This file was deleted.

‎CHANGELOG.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## v4.0
4+
5+
- The `notify` property is no longer injected into routes and controllers by default. You should now
6+
use `notify: Ember.inject.service()`
7+
- The property names have changed from `message` and `raw` to `text` and `html`
8+
- The `Notify.*` helper methods (`info`, `success`, `warning`, `alert` and `error`) no longer return
9+
a Promise, they return a `Message` instance
10+
11+
312
## v3.0
413

514
v3.0 uses a component + helper architecture that removes several hacks in previous versions.
@@ -9,4 +18,4 @@ v3.0 uses a component + helper architecture that removes several hacks in previo
918
- ember-cli is now required for v3.0. Projects that don't use ember-cli will need to stay on the v2.0 branch
1019
- You now need to add `{{ember-notify}}` to one of your templates, usually in `application.hbs`
1120
- Bootstrap styling is now selected using the `messageStyle` property on the component: `{{ember-notify messageStyle='bootstrap'}}`
12-
- If you're using `message.send('close')`, this will need to be changed to `message.set('visible', false)`
21+
- If you were using `message.send('close')`, this will need to be changed to `message.set('visible', false)`

‎README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ Or you can control when each message is closed:
4141
var message = Notify.alert('You can control how long it\'s displayed', {
4242
closeAfter: 10000 // or set to null to disable auto-hiding
4343
});
44-
message.set('visible', false); // and you can hide messages programmatically.
44+
message.set('visible', false); // and you can hide messages programatically.
4545
```
4646

47-
The Notify methods (`info`, `success`, `warning`, `alert` and `error`) all return a Promise for an instance of `Message`. You can use this object to change the `message` property, or to programatically hide the message by setting `visible` to `false`.
48-
4947
You can specify raw HTML:
5048

5149
```js
52-
Notify.info({raw: '<div class="my-div">Hooray!</div>'});
50+
Notify.info({html: '<div class="my-div">Hooray!</div>'});
5351
```
5452

5553
Rounded corners, if that's your thing:

‎addon/components/ember-notify.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default Ember.Component.extend({
1616
init: function() {
1717
this._super();
1818
this.set('messages', Ember.A());
19-
this.set('source.target', this);
19+
this.get('source').setTarget(this);
2020

2121
var style = this.get('messageStyle'), theme;
2222
switch (style) {
@@ -37,7 +37,7 @@ export default Ember.Component.extend({
3737
this.set('theme', theme);
3838
},
3939
willDestroyElement: function() {
40-
this.set('source.target', null);
40+
this.get('source').setTarget(null);
4141
},
4242
show: function(message) {
4343
if (this.get('isDestroyed')) return;
@@ -67,15 +67,15 @@ export var FoundationTheme = Theme.extend({
6767
export var BootstrapTheme = Theme.extend({
6868
classNamesFor(message) {
6969
var type = message.get('type');
70-
var classNames = ['alert', type];
71-
if (type === 'alert' || type === 'error') classNames.push('danger');
70+
if (type === 'alert' || type === 'error') type = 'danger';
71+
var classNames = ['alert', `alert-${type}`];
7272
return classNames.join(' ');
7373
}
7474
});
7575

7676
export var RefillsTheme = Theme.extend({
77-
typeCss: Ember.computed('type', function() {
78-
var type = this.get('message.type');
77+
classNamesFor(message) {
78+
var type = message.get('type');
7979
var typeMapping = {
8080
success: 'success',
8181
alert: 'error',
@@ -84,5 +84,5 @@ export var RefillsTheme = Theme.extend({
8484
warning: 'alert'
8585
};
8686
return 'flash-' + typeMapping[type];
87-
})
87+
}
8888
});

‎addon/components/ember-notify/message.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export default Ember.Component.extend({
1717

1818
init: function() {
1919
this._super();
20+
// indicate that the message is now being displayed
21+
if (this.get('message.visible') === undefined) {
22+
// should really be in didInsertElement but Glimmer doesn't allow this
23+
this.set('message.visible', true);
24+
}
2025
this.run = Runner.create({
2126
// disable all the scheduling in tests
2227
disabled: Ember.testing && !Notify.testing
@@ -48,9 +53,8 @@ export default Ember.Component.extend({
4853

4954
actions: {
5055
close: function() {
51-
if (!this.get('message.visible')) {
52-
return;
53-
}
56+
if (this.get('message.closed')) return;
57+
this.set('message.closed', true);
5458
this.set('message.visible', false);
5559
var removeAfter = this.get('message.removeAfter') || this.constructor.removeAfter;
5660
if (removeAfter) {
@@ -60,10 +64,10 @@ export default Ember.Component.extend({
6064
remove();
6165
}
6266
function remove() {
63-
/* debug */ return;
6467
var parentView = this.get('parentView');
65-
if (this.get('isDestroyed') || !parentView) return;
68+
if (this.get('isDestroyed') || !parentView || !parentView.get('messages')) return;
6669
parentView.get('messages').removeObject(this.get('message'));
70+
this.set('message.visible', null);
6771
}
6872
}
6973
}

‎addon/index.js

+18-65
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Ember from 'ember';
2-
import computed from 'ember-new-computed';
2+
import Message from './message';
33

44
function aliasToShow(type) {
55
return function(message, options) {
@@ -15,93 +15,46 @@ var Notify = Ember.Service.extend({
1515
alert: aliasToShow('alert'),
1616
error: aliasToShow('error'),
1717

18-
init: function() {
18+
init() {
1919
this.pending = [];
2020
},
2121

22-
show: function(type, message, options) {
23-
if (typeof message === 'object') {
24-
options = message;
25-
message = null;
22+
show(type, text, options) {
23+
if (typeof text === 'object') {
24+
options = text;
25+
text = null;
2626
}
27-
message = Ember.merge({
28-
message: message,
27+
var message = Message.create(Ember.merge({
28+
text: text,
2929
type: type
30-
}, options);
30+
}, options));
3131
var target = this.get('target');
32-
var promise;
3332
if (target) {
34-
var messageObj = target.show(message);
35-
promise = Ember.RSVP.resolve(messageObj);
33+
target.show(message);
3634
}
3735
else {
38-
promise = new Ember.RSVP.Promise(resolve => this.pending.push({
39-
message: message,
40-
resolve: resolve
41-
}));
36+
this.pending.push(message);
4237
}
43-
return MessagePromise.create({
44-
message: message,
45-
promise: promise
46-
});
47-
},
48-
49-
create: function(component) {
50-
return Notify.create({
51-
target: component
52-
});
38+
return message;
5339
},
5440

55-
showPending: Ember.observer('target', function() {
56-
var target = this.get('target');
41+
setTarget(target) {
42+
this.set('target', target);
5743
if (target) {
58-
this.pending.map(function(pending) {
59-
var messageObj = target.show(pending.message);
60-
pending.resolve(messageObj);
61-
});
44+
this.pending.map(message => target.show(message));
6245
this.pending = [];
6346
}
64-
})
47+
}
6548

6649
}).reopenClass({
6750
// set to true to disable testing optimizations that are enabled when Ember.testing is true
6851
testing: false
6952
});
7053

71-
export default Notify.extend({
72-
property: function() {
54+
export default Notify.reopenClass({
55+
property() {
7356
return Ember.computed(function() {
7457
return Notify.create();
7558
});
76-
},
77-
create: function() {
78-
return Notify.create();
79-
},
80-
target: computed({
81-
get() {
82-
return this._target;
83-
},
84-
set(key, val) {
85-
Ember.assert("Only one {{ember-notify}} should be used without a source property. " +
86-
"If you want more than one then use {{ember-notify source=someProperty}}",
87-
!this._primary || this._primary.get('isDestroyed')
88-
);
89-
this._target = val;
90-
return this._target;
91-
}
92-
})
93-
94-
});
95-
96-
var MessagePromise = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin, {
97-
set: function(key, val) {
98-
// if the message hasn't been displayed then set the value on the message hash
99-
if (!this.get('content')) {
100-
this.message[key] = val;
101-
return this;
102-
}
103-
else {
104-
return this._super(key, val);
105-
}
10659
}
10760
});

‎addon/message.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Ember from 'ember';
22

33
export default Ember.Object.extend({
4-
message: null,
5-
raw: '',
4+
text: null,
5+
html: '',
66
type: 'info',
77
closeAfter: undefined,
8-
visible: true,
8+
visible: undefined,
99
classNames: []
1010
});
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{{#each messages as |message|}}
2-
{{ember-notify/message message=message theme=theme closeAfter=closeAfter class='ember-notify clearfix'}}
2+
{{ember-notify/message
3+
message=message theme=theme closeAfter=closeAfter class='ember-notify clearfix'}}
34
{{/each}}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<a {{action 'close'}} class='close'>&times;</a>
2-
<span class='message'>{{message.message}}{{{message.raw}}}</span>
2+
<span class='message'>{{message.text}}{{{message.html}}}</span>

‎bower.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
{
22
"name": "ember-notify",
33
"dependencies": {
4-
"ember": "components/ember#beta",
4+
"ember": "1.13.3",
55
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
66
"ember-cli-test-loader": "ember-cli-test-loader#0.1.3",
7-
"ember-mocha": "~0.4.0",
7+
"ember-mocha": "~0.8.0",
88
"ember-load-initializers": "ember-cli/ember-load-initializers#0.1.5",
99
"ember-resolver": "~0.1.18",
10-
"jquery": "^1.11.1"
11-
},
12-
"resolutions": {
13-
"ember": "beta"
10+
"jquery": "^1.11.1",
11+
"loader.js": "ember-cli/loader.js#3.2.0"
1412
}
1513
}

‎ember-cli-build.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
/* global require, module */
2-
var EmberApp = require('ember-cli/lib/broccoli/ember-addon');
1+
/* jshint node: true */
2+
var EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
33

44
module.exports = function(defaults) {
5-
var app = new EmberApp(defaults, {
6-
// Add options here
7-
});
8-
9-
/*
10-
This build file specifes the options for the dummy test app of this
11-
addon, located in `/tests/dummy`
12-
This build file does *not* influence how the addon or the app using it
13-
behave. You most likely want to be modifying `./index.js` or app's build file
14-
*/
15-
5+
var app = new EmberAddon(defaults, {});
166
return app.toTree();
177
};

‎package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,19 @@
1919
"license": "MIT",
2020
"devDependencies": {
2121
"broccoli-asset-rev": "^2.0.2",
22-
"ember-cli": "1.13.1",
22+
"ember-cli": "1.13.6",
2323
"ember-cli-app-version": "0.4.0",
2424
"ember-cli-dependency-checker": "^1.0.0",
2525
"ember-cli-htmlbars-inline-precompile": "^0.1.1",
2626
"ember-cli-ic-ajax": "0.2.1",
2727
"ember-cli-inject-live-reload": "^1.3.0",
28-
"ember-cli-mocha": "^0.4.0",
28+
"ember-cli-mocha": "0.9.1",
2929
"ember-cli-release": "0.2.3",
3030
"ember-cli-uglify": "^1.0.1",
3131
"ember-devtools": "^3.2.0",
3232
"ember-disable-prototype-extensions": "^1.0.0",
3333
"ember-disable-proxy-controllers": "^1.0.0",
3434
"ember-export-application-global": "^1.0.2",
35-
"ember-new-computed": "1.0.0",
3635
"ember-try": "0.0.6",
3736
"object-assign": "^2.0.0"
3837
},

‎tests/acceptance/injection-test.js

-50
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.