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

Destroy a message with click throw a error #2

Closed
felipehw opened this issue Feb 3, 2015 · 2 comments
Closed

Destroy a message with click throw a error #2

felipehw opened this issue Feb 3, 2015 · 2 comments

Comments

@felipehw
Copy link

felipehw commented Feb 3, 2015

When a message is destroyed with click (invoking public destroyMessage() of flash/object) the _destroyLater() try destroy again the object after timeout ... and throws a error. If the message clicked is on the middle of array ... the others messages (newer) are not erased by timeout.

One possible solution is cancel the try of _destroyLater() when _destroyMessage() is invoked (flash/object) :

  _destroyLaterTimer: null,
  _destroyLater: function() {
    var defaultTimeout = get(this, 'defaultTimeout');
    var timeout        = getWithDefault(this, 'timeout', defaultTimeout);

    this.set('_destroyLaterTimer', run.later(this, '_destroyMessage', timeout));
  }.on('init'),

  _destroyMessage: function() {
    var queue = get(this, 'queue');

    run.cancel(this.get('_destroyLaterTimer'));
    set(this, 'isDestroyed', true);
    if (queue) {
      queue.removeObject(this);
    }
  }

Other solution is verify if the object is already destroyed when _destroyMessage() is invoked:

  _destroyMessage: function() {
    var queue = get(this, 'queue');
    if ( queue && !this.get('isDestroyed') ) {
      queue.removeObject(this);
      set(this, 'isDestroyed', true);
    }   
  }
@poteto
Copy link
Collaborator

poteto commented Feb 3, 2015

@felipehw I have to admit I completely forgot about cancelling, so thanks for catching this! Give 0.2.0 a whirl and let me know if you still get the same error.

@poteto poteto closed this as completed Feb 3, 2015
@abhilashlr
Copy link
Contributor

@poteto is there a way by which one can close the current flash message? lets say my template has an anchor tag which will close/delete the flash message.

Ember.get(this, 'flashMessages').clearMessages();

will clear all messages, but in this use-case the messages stack one on top of the other based on priority. So this is how it is required:

{{#flash-message flash=flash as |component flash|}}
    {{{flash.message}}}
    <a href="#" ______> x </a> -- click this and the currently selected flash message should disappear.
{{/flash-message}}

Also, would like to know if there is a way to prevent the click on the flash message. Only click on the cross will close the flash message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants