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

Changed: added marker name to events fired by model.MarkerCollection. #912

Merged
merged 2 commits into from
Apr 6, 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
4 changes: 2 additions & 2 deletions src/model/markercollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class MarkerCollection {
const marker = new Marker( markerName, liveRange );

this._markers.set( markerName, marker );
this.fire( 'add', marker );
this.fire( 'add:' + markerName, marker );

return marker;
}
Expand All @@ -117,7 +117,7 @@ export default class MarkerCollection {

if ( oldMarker ) {
this._markers.delete( markerName );
this.fire( 'remove', oldMarker );
this.fire( 'remove:' + markerName, oldMarker );

this._destroyMarker( oldMarker );

Expand Down
16 changes: 8 additions & 8 deletions tests/model/markercollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe( 'MarkerCollection', () => {
} );

describe( 'set', () => {
it( 'should create a marker, fire add event and return true', () => {
it( 'should create a marker, fire add:<markerName> event and return true', () => {
sinon.spy( markers, 'fire' );

const result = markers.set( 'name', range );
Expand All @@ -48,18 +48,18 @@ describe( 'MarkerCollection', () => {
expect( result ).to.equal( marker );
expect( marker.name ).to.equal( 'name' );
expect( marker.getRange().isEqual( range ) ).to.be.true;
expect( markers.fire.calledWithExactly( 'add', marker ) ).to.be.true;
expect( markers.fire.calledWithExactly( 'add:name', marker ) ).to.be.true;
} );

it( 'should fire remove event, and create a new marker if marker with given name was in the collection', () => {
it( 'should fire remove:<markerName> event, and create a new marker if marker with given name was in the collection', () => {
const marker1 = markers.set( 'name', range );

sinon.spy( markers, 'fire' );

const marker2 = markers.set( 'name', range2 );

expect( markers.fire.calledWithExactly( 'remove', marker1 ) ).to.be.true;
expect( markers.fire.calledWithExactly( 'add', marker2 ) ).to.be.true;
expect( markers.fire.calledWithExactly( 'remove:name', marker1 ) ).to.be.true;
expect( markers.fire.calledWithExactly( 'add:name', marker2 ) ).to.be.true;

expect( marker2.name ).to.equal( 'name' );
expect( marker2.getRange().isEqual( range2 ) ).to.be.true;
Expand Down Expand Up @@ -113,15 +113,15 @@ describe( 'MarkerCollection', () => {
} );

describe( 'remove', () => {
it( 'should remove marker, return true and fire remove event', () => {
it( 'should remove marker, return true and fire remove:<markerName> event', () => {
const marker = markers.set( 'name', range );

sinon.spy( markers, 'fire' );

const result = markers.remove( 'name' );

expect( result ).to.be.true;
expect( markers.fire.calledWithExactly( 'remove', marker ) ).to.be.true;
expect( markers.fire.calledWithExactly( 'remove:name', marker ) ).to.be.true;
expect( markers.get( 'name' ) ).to.be.null;
} );

Expand Down Expand Up @@ -158,7 +158,7 @@ describe( 'MarkerCollection', () => {
const result = markers.remove( marker );

expect( result ).to.be.true;
expect( markers.fire.calledWithExactly( 'remove', marker ) ).to.be.true;
expect( markers.fire.calledWithExactly( 'remove:name', marker ) ).to.be.true;
expect( markers.get( 'name' ) ).to.be.null;
} );
} );
Expand Down