Browse Source

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.
Aleksander Nowodzinski 8 years ago
parent
commit
fd2c02b7fa

+ 6 - 0
packages/ckeditor5-utils/src/observablemixin.js

@@ -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 => {

+ 8 - 0
packages/ckeditor5-utils/tests/observablemixin.js

@@ -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() );