Skip to content

Commit

Permalink
Trigger nameChanged event #17
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserf committed Jul 30, 2015
1 parent 3819d41 commit 6784975
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/record/anonymous-record.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var Record = require( './record' );
var Record = require( './record' ),
EventEmitter = require( 'component-emitter' );

/**
* An AnonymousRecord is a record without a predefined name. It
Expand Down Expand Up @@ -27,6 +28,8 @@ var AnonymousRecord = function( recordHandler ) {
this._proxyMethod( 'discard' );
};

EventEmitter( AnonymousRecord.prototype );

/**
* Proxies the actual record's get method. It is valid
* to call get prior to setName - if no record exists,
Expand Down Expand Up @@ -131,6 +134,8 @@ AnonymousRecord.prototype.setName = function( recordName ) {
for( i = 0; i < this._subscriptions.length; i++ ) {
this._record.subscribe( this._subscriptions[ i ] );
}

this.emit( 'nameChanged', recordName );
};

/**
Expand Down
10 changes: 10 additions & 0 deletions test-unit/unit/record/anonymous-recordSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,14 @@ describe( 'anonymous record allows switching of underlying records', function(){

expect( errorCallback ).not.toHaveBeenCalled();
});

it( 'emits an nameChanged event when setName is called', function() {
var readyEventListener = jasmine.createSpy( 'nameChanged' );
anonymousRecord.on( 'nameChanged', readyEventListener );

anonymousRecord.setName( 'recordC' );

expect( readyEventListener ).toHaveBeenCalled();
expect( readyEventListener ).toHaveBeenCalledWith( 'recordC' );
} );
});

0 comments on commit 6784975

Please sign in to comment.