Skip to content

Commit

Permalink
Fixes #32 Subscribing to empty list returns object instead of array
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserf committed Dec 12, 2015
1 parent c9a74f4 commit 6d6a8c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/record/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ List.prototype.subscribe = function() {
throw new Error( 'path is not supported for List.subscribe' );
}

parameters.callback = function( callback ) {
callback( this.getEntries() );
}.bind( this, parameters.callback );

this._record.subscribe( parameters );
};

Expand Down
14 changes: 12 additions & 2 deletions test-unit/unit/record/list-change-listenerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,25 @@ describe( 'lists contain arrays of record names', function(){
return callback;
}

it( 'creates the list', function(){
it( 'creates the list', function( done ){
var callback = jasmine.createSpy( 'empty-subscribe' );

list = new List( recordHandler, 'someList', {} );

recordHandler._$handle({
topic: 'R',
action: 'R',
data: [ 'someList', 1, '[]' ]
data: [ 'someList', 1, '{}' ]
});

expect( list.getEntries() ).toEqual( [] );
expect( list.isEmpty() ).toBe( true );

list.whenReady( function() {
list.subscribe( callback, true );
expect( callback ).toHaveBeenCalledWith( [] );
done();
});
});

it( 'works without any listeners', function(){
Expand Down

0 comments on commit 6d6a8c8

Please sign in to comment.