Skip to content

Instantly share code, notes, and snippets.

@mupkoo
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mupkoo/9eb13ef72a2f546a2367 to your computer and use it in GitHub Desktop.
Save mupkoo/9eb13ef72a2f546a2367 to your computer and use it in GitHub Desktop.
Ember Flash messages view
Uncaught TypeError: Cannot read property 'send' of undefined vendor.js:32923
import Ember from 'ember';
var Flash = Ember.ContainerView.extend({
rootElement: null,
container: null,
classNames: [ 'flash-messages' ],
error: function (message) { return this.show(message, 'error'); },
info: function (message) { return this.show(message, 'info'); },
success: function (message) { return this.show(message, 'success'); },
show: function (message, type) {
var view = this.createChildView(Message, {
message: message,
type: type
});
return this.pushObject(view);
},
init: function () {
this._super();
var self = this;
var observer = {
arrayWillChange: function() {
self.appendTo(document.body);
self.removeArrayObserver(observer);
}
};
this.addArrayObserver(observer);
}
});
var Message = Ember.View.extend({
classNameBindings: [ ':flash-message', 'view.type', ':visible' ],
defaultTemplate: Ember.Handlebars.compile('<a class="close" {{ action "close" }}>&times;</a><p>{{ view.message }}</p>'),
actions: {
close: function () {
var parent = this.get('parentView');
console.log(parent);
if (parent) {
parent.removeObject(this);
}
}
}
});
export default Flash.create();
// ...
ActionHelper.registerAction = function(actionNameOrPath, options, allowedKeys) {
var actionId = uuid();
ActionManager.registeredActions[actionId] = {
eventName: options.eventName,
handler: function handleRegisteredAction(event) {
if (!isAllowedEvent(event, allowedKeys)) { return true; }
if (options.preventDefault !== false) {
event.preventDefault();
}
if (options.bubbles === false) {
event.stopPropagation();
}
var target = options.target;
var parameters = options.parameters;
var eventName = options.eventName;
var actionName;
if (target.target) {
target = handlebarsGet(target.root, target.target, target.options);
} else {
target = target.root;
}
if (options.boundProperty) {
actionName = resolveParams(parameters.context, [actionNameOrPath], { types: ['ID'], data: parameters.options.data })[0];
if (typeof actionName === 'undefined' || typeof actionName === 'function') {
Ember.deprecate("You specified a quoteless path to the {{action}} helper '" + actionNameOrPath + "' which did not resolve to an actionName. Perhaps you meant to use a quoted actionName? (e.g. {{action '" + actionNameOrPath + "'}}).");
actionName = actionNameOrPath;
}
}
if (!actionName) {
actionName = actionNameOrPath;
}
run(function runRegisteredAction() {
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This is where the error is triggered from !!!
// !!! `target` is the undefined !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (target.send) {
target.send.apply(target, args(parameters, actionName));
} else {
Ember.assert("The action '" + actionName + "' did not exist on " + target, typeof target[actionName] === 'function');
target[actionName].apply(target, args(parameters));
}
});
}
};
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment