Skip to content

Commit

Permalink
- lazy attribute getter included into implicit methods chaining
Browse files Browse the repository at this point in the history
- improved test coverage for lazy attributes
  • Loading branch information
Nickolay Platonov committed Oct 5, 2010
1 parent d4797d7 commit 2786c9e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
14 changes: 8 additions & 6 deletions lib/KiokuJS/Feature/Attribute/Lazy.js
Expand Up @@ -31,26 +31,28 @@ Role('KiokuJS.Feature.Attribute.Lazy', {
var value = original.call(this)
var self = this

var cont = Joose.top.__GLOBAL_CNT__ || new JooseX.CPS.Continuation()

if (value instanceof KiokuJS.Reference && value.type == 'lazy') {

var ID = value.ID

if (!scope) throw "No scope provided to fetch the lazy reference in. Reference ID [" + ID + "]"

return TRY(function () {
return cont.TRY(function () {

scope.fetch([ ID ], [ ID ], 0).andThen(function (obj) {

me.setValueTo(self, obj)

this.CONTINUE(obj)
})
})
this.CONT.CONTINUE(obj)
}, self)
}, self)
}

return TRY(function () {
return cont.TRY(function () {
this.CONT.CONTINUE(value)
})
}, self)
}
},

Expand Down
38 changes: 24 additions & 14 deletions lib/KiokuJS/Test/Fixture/Lazy.js
Expand Up @@ -59,15 +59,14 @@ Class('KiokuJS.Test.Fixture.Lazy', {

instance.getLazyAttr1().andThen(function (value) {
t.ok(value == bigArray, 'Correct result from getter #2')

//======================================================================================================================================================================================================================================================
t.diag('Populating')

var scope = handle.newScope()

scope.storeAs({ instance : instance }).now()
})


//======================================================================================================================================================================================================================================================
t.diag('Populating')

var scope = handle.newScope()

scope.storeAs({ instance : instance }).now()
},


Expand All @@ -80,13 +79,24 @@ Class('KiokuJS.Test.Fixture.Lazy', {
//======================================================================================================================================================================================================================================================
t.diag('Retrieving lazy attributes')

debugger

t.ok(instance && instance.usualAttr == 'foo', 'Instance seems to be restored correctly')
t.ok(instance && instance.usualAttr == 'foo', 'Instance seems to be restored correctly #1')

this.CONTINUE()

}, this)
instance.getLazyAttr3().andThen(function (value) {
t.ok(value == 'yo', 'Instance seems to be restored correctly #2')

instance.getLazyAttr1(newScope).andThen(function (value1) {
t.isDeeply(value1, [ 1, 2, 3 ], 'Value of `lazyAttr1` is correct')

instance.getLazyAttr2(newScope).andThen(function (value2) {
t.isDeeply(value2, [ 1, 2, 3 ], 'Value of `lazyAttr2` is correct')

t.ok(value1 == value2, 'Lazy attribute has been correctly pulled from scope')

this.CONT.CONTINUE()
})
})
})
})
}
}
}
Expand Down

0 comments on commit 2786c9e

Please sign in to comment.