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

Commit

Permalink
Merge pull request #210 from ckeditor/t/5
Browse files Browse the repository at this point in the history
Other: `ObservableMixin#unbind` should not throw if used for an attribute which is not bound. Closes #5.
  • Loading branch information
oleq authored Nov 27, 2017
2 parents d8443e2 + 6f0e5ba commit 848a818
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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

0 comments on commit 848a818

Please sign in to comment.