-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spiked out a basic implementation of ObjectWrapper#watch (see #49)
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
describe("Lazy", function() { | ||
describe("watch", function() { | ||
it("watches an object for changes to the specified property", function() { | ||
var object = {}, | ||
callback = jasmine.createSpy(); | ||
|
||
Lazy(object).watch('foo').each(callback); | ||
|
||
object.foo = 1; | ||
object.foo = 'bar'; | ||
object.foo = null; | ||
|
||
expect(callback.callCount).toBe(3); | ||
expect(callback.calls[0].args).toEqual([1, 0]); | ||
expect(callback.calls[1].args).toEqual(['bar', 1]); | ||
expect(callback.calls[2].args).toEqual([null, 2]); | ||
}); | ||
|
||
it("provides access to map, filter, etc.", function() { | ||
function upcase(str) { | ||
return str.toUpperCase(); | ||
} | ||
|
||
function blank(str) { | ||
return str.length === 0; | ||
} | ||
|
||
var object = {}, | ||
callback = jasmine.createSpy(); | ||
|
||
Lazy(object).watch('foo').compact().map(upcase).each(callback); | ||
|
||
object.foo = ''; | ||
object.foo = 'bar'; | ||
object.foo = null; | ||
|
||
expect(callback.callCount).toBe(1); | ||
|
||
// Given the implementation, I don't think there's a great way around | ||
// this? (Having to pass the index of the assignment rather than the | ||
// "adjusted" index.) | ||
expect(callback.calls[0].args).toEqual(['BAR', 1]); | ||
}); | ||
}); | ||
}); |