Skip to content

Commit

Permalink
fix: setting anonymous record with same name
Browse files Browse the repository at this point in the history
Setting anonymous record with same name discards and resubscribes
the same record, it should just ignore it

Fixes deepstreamIO#312
  • Loading branch information
yasserf committed Apr 8, 2017
1 parent d7822f5 commit 9809b46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/record/anonymous-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ AnonymousRecord.prototype.unsubscribe = function () {
* @returns {void}
*/
AnonymousRecord.prototype.setName = function (recordName) {
if (this.name === recordName) {
return
}

this.name = recordName

let i
Expand Down
7 changes: 7 additions & 0 deletions test-unit/unit/record/anonymous-recordSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ describe('anonymous record allows switching of underlying records', () => {
expect(recordHandler._connection.lastSendMessage).toBe(msg('R|CR|recordA+'))
})

it('does nothing if same name is set again', () => {
recordHandler._connection.lastSendMessage = null
anonymousRecord.setName('recordA')
expect(anonymousRecord.name).toBe('recordA')
expect(recordHandler._connection.lastSendMessage).toBe(null)
})

it('updates subscriptions once the record is ready', () => {
expect(firstnameCallback).not.toHaveBeenCalled()
expect(generalCallback).not.toHaveBeenCalled()
Expand Down

0 comments on commit 9809b46

Please sign in to comment.