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 dismounting groups throwing unknown id error #83

Closed
wants to merge 1 commit into from
Closed
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
146 changes: 82 additions & 64 deletions examples/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ class Main extends Component {
});
}

onDismountToggle () {
this.setState({
dismountGroups: !this.state.dismountGroups
});
}

onPrefixChange (event) {
const target = event.currentTarget;

Expand Down Expand Up @@ -299,72 +305,84 @@ class Main extends Component {
<p>
This example has a group of lists that you can drag items between
</p>
<p>
{'Dismount reorder: '}
<input
type="checkbox"
value={this.state.dismountGroups || false}
onChange={this.onDismountToggle.bind(this)}
/>
</p>

<Reorder
reorderId="listA"
reorderGroup="reorderGroup"
component="ul"
className={[classNames.myList, classNames.multiList].join(' ')}
placeholderClassName={classNames.placeholder}
draggedClassName={classNames.dragged}
onReorder={this.onReorderGroup.bind(this)}
>
{
this.state.listA.map(function (item) {
return (
<li
key={item.name}
className={[classNames.listItem, classNames.multiListItem].join(' ')}
style={{color: item.color}}
>
<div className={classNames.contentHolder}>
<span className={classNames.itemName}>
{item.name}
</span>
<input
className={classNames.input}
type="text"
defaultValue="Change me, I sort of retain this state!"
/>
</div>
</li>
);
}.bind(this)).toArray()
}
</Reorder>
{!this.state.dismountGroups &&
<Reorder
reorderId="listA"
reorderGroup="reorderGroup"
component="ul"
className={[classNames.myList, classNames.multiList].join(' ')}
placeholderClassName={classNames.placeholder}
draggedClassName={classNames.dragged}
onReorder={this.onReorderGroup.bind(this)}
>
{
this.state.listA.map(function (item) {
return (
<li
key={item.name}
className={[classNames.listItem, classNames.multiListItem].join(' ')}
style={{color: item.color}}
>
<div className={classNames.contentHolder}>
<span className={classNames.itemName}>
{item.name}
</span>
<input
className={classNames.input}
type="text"
defaultValue="Change me, I sort of retain this state!"
/>
</div>
</li>
);
}.bind(this)).toArray()
}
</Reorder>
}

<Reorder
reorderId="listB"
reorderGroup="reorderGroup"
component="ul"
className={[classNames.myList, classNames.multiList].join(' ')}
placeholderClassName={classNames.placeholder}
draggedClassName={classNames.dragged}
onReorder={this.onReorderGroup.bind(this)}
>
{
this.state.listB.map(function (item) {
return (
<li
key={item.name}
className={[classNames.listItem, classNames.multiListItem].join(' ')}
style={{color: item.color}}
>
<div className={classNames.contentHolder}>
<span className={classNames.itemName}>
{item.name}
</span>
<input
className={classNames.input}
type="text"
defaultValue="Change me, I sort of retain this state!"
/>
</div>
</li>
);
}.bind(this)).toArray()
}
</Reorder>
{!this.state.dismountGroups &&
<Reorder
reorderId="listB"
reorderGroup="reorderGroup"
component="ul"
className={[classNames.myList, classNames.multiList].join(' ')}
placeholderClassName={classNames.placeholder}
draggedClassName={classNames.dragged}
onReorder={this.onReorderGroup.bind(this)}
>
{
this.state.listB.map(function (item) {
return (
<li
key={item.name}
className={[classNames.listItem, classNames.multiListItem].join(' ')}
style={{color: item.color}}
>
<div className={classNames.contentHolder}>
<span className={classNames.itemName}>
{item.name}
</span>
<input
className={classNames.input}
type="text"
defaultValue="Change me, I sort of retain this state!"
/>
</div>
</li>
);
}.bind(this)).toArray()
}
</Reorder>
}
</div>
);
}
Expand Down
16 changes: 8 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@
function registerReorderComponent (reorderId, reorderGroup, callback) {
validateComponentIdAndGroup(reorderId, reorderGroup);

if (reorderId in reorderComponents) {
throw new Error('Duplicate reorderId: ' + reorderId);
}

if (typeof reorderGroup !== 'undefined') {
if ((reorderGroup in reorderGroups) && (reorderId in reorderGroups[reorderGroup])) {
throw new Error('Duplicate reorderId: ' + reorderId + ' in reorderGroup: ' + reorderGroup);
Expand All @@ -70,17 +66,17 @@
reorderGroups[reorderGroup] = reorderGroups[reorderGroup] || {};
reorderGroups[reorderGroup][reorderId] = callback;
} else {
if (reorderId in reorderComponents) {
throw new Error('Duplicate reorderId: ' + reorderId);
}

reorderComponents[reorderId] = callback;
}
}

function unregisterReorderComponent (reorderId, reorderGroup) {
validateComponentIdAndGroup(reorderId, reorderGroup);

if (!(reorderId in reorderComponents)) {
throw new Error('Unknown reorderId: ' + reorderId);
}

if (typeof reorderGroup !== 'undefined') {
if (!(reorderGroup in reorderGroups)) {
throw new Error('Unknown reorderGroup: ' + reorderGroup);
Expand All @@ -92,6 +88,10 @@

delete reorderGroups[reorderGroup][reorderId];
} else {
if (!(reorderId in reorderComponents)) {
throw new Error('Unknown reorderId: ' + reorderId);
}

delete reorderComponents[reorderId];
}
}
Expand Down