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

Commit 848a818

Browse files
authored
Merge pull request #210 from ckeditor/t/5
Other: `ObservableMixin#unbind` should not throw if used for an attribute which is not bound. Closes #5.
2 parents d8443e2 + 6f0e5ba commit 848a818

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/observablemixin.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ const ObservableMixin = {
216216

217217
unbindAttrs.forEach( attrName => {
218218
const binding = boundAttributes.get( attrName );
219+
220+
// Nothing to do if the binding is not defined
221+
if ( !binding ) {
222+
return;
223+
}
224+
219225
let toObservable, toAttr, toAttrs, toAttrBindings;
220226

221227
binding.to.forEach( to => {

tests/observablemixin.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,14 @@ describe( 'Observable', () => {
739739
observable.unbind();
740740
} );
741741

742+
it( 'should not fail when unbinding attribute that is not bound', () => {
743+
const observable = new Observable();
744+
745+
observable.bind( 'foo' ).to( car, 'color' );
746+
747+
expect( () => observable.unbind( 'bar' ) ).to.not.throw();
748+
} );
749+
742750
it( 'should throw when non-string attribute is passed', () => {
743751
expect( () => {
744752
car.unbind( new Date() );

0 commit comments

Comments
 (0)