Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Don't throw error when trying to unbind attribute that is not bound. #210

Merged
merged 2 commits into from
Nov 27, 2017
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
6 changes: 6 additions & 0 deletions src/observablemixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ const ObservableMixin = {

unbindAttrs.forEach( attrName => {
const binding = boundAttributes.get( attrName );

// Nothing to do if the binding is not defined
if ( !binding ) {
return;
}

let toObservable, toAttr, toAttrs, toAttrBindings;

binding.to.forEach( to => {
Expand Down
8 changes: 8 additions & 0 deletions tests/observablemixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,14 @@ describe( 'Observable', () => {
observable.unbind();
} );

it( 'should not fail when unbinding attribute that is not bound', () => {
const observable = new Observable();

observable.bind( 'foo' ).to( car, 'color' );

expect( () => observable.unbind( 'bar' ) ).to.not.throw();
} );

it( 'should throw when non-string attribute is passed', () => {
expect( () => {
car.unbind( new Date() );
Expand Down