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

Fix for orderable unsubscribing #538

Merged
merged 1 commit into from
Feb 20, 2017

Conversation

gerhardboer
Copy link
Contributor

What kind of change does this PR introduce? (check one with "x")

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior? (You can also link to an open issue here)
reproducable on https://swimlane.github.io/ngx-datatable/#

When toggling the Name column to off and then clicking the 'Company' column, a stacktrace pops up in the console.
Error: object unsubscribed at t.h (polyfills.js:1651) at new t (polyfills.js:1616) at t.next (polyfills.js:1609) ...

Problem
The KeyValueDiffer is used with an Array, which means it will use the index of the array to check for diffs.
When the Name column is removed the column-array us spliced, so no gaps occure.

This will cause the differ to think that the actual removed column was on the last index, since it went from [0, 1, 2] to [0,1]. The Company column was on this index, so it unsubscribed from the dragStart and dragEnd event emitters of the Company column, instead of the Name column.

Fix
By transforming the QueryElement Array into a map with the column.$$id as key, the KeyValueDiffer uses the column.$$id to diff the objects.

What is the new behavior?
The Company column does not lose its subscription to the draggable directive.

Does this PR introduce a breaking change? (check one with "x")

  • Yes
  • No

If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...

Other information:

@amcdnl amcdnl merged commit f774ad9 into swimlane:master Feb 20, 2017
@amcdnl
Copy link
Contributor

amcdnl commented Feb 20, 2017

Awesome idea 👍

rsparrow pushed a commit to rsparrow/ngx-datatable that referenced this pull request Jun 2, 2017
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

Successfully merging this pull request may close these issues.

2 participants