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

General cleanup of the flash object and component #108

Merged
merged 1 commit into from
Oct 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions addon/components/flash-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ import layout from '../templates/components/flash-message';
import computed from 'ember-new-computed';

const {
Handlebars,
String: { classify, htmlSafe },
Component,
getWithDefault,
warn,
run,
on,
get,
set,
String: { classify },
Handlebars: { SafeString }
} = Ember;
const {
escapeExpression
} = Handlebars.Utils;
readOnly,
bool
} = computed;

export default Ember.Component.extend({
export default Component.extend({
layout,
classNameBindings: [ 'alertType', 'active', 'exiting' ],
classNameBindings: ['alertType', 'active', 'exiting'],
active: false,
messageStyle: 'bootstrap',
showProgressBar: computed.readOnly('flash.showProgress'),
exiting: computed.readOnly('flash.exiting'),
showProgressBar: readOnly('flash.showProgress'),
exiting: readOnly('flash.exiting'),

alertType: computed('flash.type', {
get() {
Expand Down Expand Up @@ -72,9 +72,8 @@ export default Ember.Component.extend({
}

const duration = getWithDefault(this, 'flash.timeout', 0);
const escapedCSS = escapeExpression(`transition-duration: ${duration}ms`);

return new SafeString(escapedCSS);
return htmlSafe(`transition-duration: ${duration}ms`);
},

set() {
Expand All @@ -100,5 +99,5 @@ export default Ember.Component.extend({
}
},

hasBlock: computed.bool('template').readOnly()
hasBlock: bool('template').readOnly()
});
39 changes: 21 additions & 18 deletions addon/flash/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,34 @@ import customComputed from '../utils/computed';
import computed from 'ember-new-computed';

const {
Object: EmberObject,
run: { later, cancel },
Evented,
on,
run,
get,
set
} = Ember;
const {
readOnly
} = computed;

export default Ember.Object.extend(Evented, {
queue: computed.readOnly('flashService.queue'),
export default EmberObject.extend(Evented, {
queue: readOnly('flashService.queue'),
totalTimeout: customComputed.add('timeout', 'extendedTimeout').readOnly(),
timer: null,
exitTimer: null,
exiting: false,

init() {
this._super(...arguments);

if (get(this, 'sticky')) {
return;
}

this._setTimer('exitTimer', 'exitMessage', get(this, 'timeout'));
this._setTimer('timer', 'destroyMessage', get(this, 'totalTimeout'));
},

destroyMessage() {
const queue = get(this, 'queue');

Expand All @@ -36,7 +50,7 @@ export default Ember.Object.extend(Evented, {
},

willDestroy() {
const timers = [ 'timer', 'exitTimer' ];
const timers = ['timer', 'exitTimer'];

timers.forEach((timer) => {
this._cancelTimer(timer);
Expand All @@ -48,26 +62,15 @@ export default Ember.Object.extend(Evented, {
// private
_guid: customComputed.guidFor('message').readOnly(),

_setInitialState: on('init', function() {
if (get(this, 'sticky')) {
return;
}

this._setTimer('exitTimer', 'exitMessage', get(this, 'timeout'));
this._setTimer('timer', 'destroyMessage', get(this, 'totalTimeout'));
}),

_setTimer(name, methodName, timeout) {
const timer = run.later(this, methodName, timeout);

set(this, name, timer);
set(this, name, later(this, methodName, timeout));
},

_cancelTimer(name) {
const timer = get(this, name);

if (timer) {
run.cancel(timer);
cancel(timer);
set(this, name, null);
}
}
Expand Down
3 changes: 1 addition & 2 deletions app/initializers/flash-messages.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import config from '../config/environment';

export function initialize() {
let application = arguments[1] || arguments[0];

const application = arguments[1] || arguments[0];
const { flashMessageDefaults } = config;
const { injectionFactories } = flashMessageDefaults;

Expand Down
11 changes: 0 additions & 11 deletions circle.yml

This file was deleted.