Skip to content

Commit

Permalink
if control or model is loaded after proxy, proxy will still work on s…
Browse files Browse the repository at this point in the history
…tatic methods
  • Loading branch information
moschel committed Dec 7, 2012
1 parent 4f65134 commit b558c9b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
8 changes: 8 additions & 0 deletions construct/proxy/proxy.js
Expand Up @@ -57,5 +57,13 @@ proxy = function( funcs ) {
}
}
can.Construct.proxy = can.Construct.prototype.proxy = proxy;
// this corrects the case where can/control loads after can/construct/proxy, so static props don't have proxy
var correctedClasses = [can.Control, can.Model],
i = 0;
for (; i < correctedClasses.length; i++ ) {
if(correctedClasses[i]){
correctedClasses[i].proxy = proxy;
}
}
return can;
});
27 changes: 21 additions & 6 deletions construct/proxy/proxy_test.js
@@ -1,20 +1,35 @@
steal('can/util', 'can/construct/proxy', function(can) {
steal('can/util', 'can/control').then('can/construct/proxy', function(can) {
var isDist = (/dist/.test(location.href));

module("can/construct/proxy");


test("proxy", function(){
test("static proxy if control is loaded first", function(){
var curVal = 0;
can.Construct("Car",{
expect(2);
can.Control("Car",{
show: function( value ) {
equals(curVal, value)
}
},{
show: function( value ) {
},{})
var cb = Car.proxy('show');
curVal = 1;
cb(1)

curVal = 2;
var cb2 = Car.proxy('show',2)
cb2();
});


test("proxy", function(){
var curVal = 0;
expect(2);
can.Construct("Car",{
show: function( value ) {
equals(curVal, value)
}
})
},{})
var cb = Car.proxy('show');
curVal = 1;
cb(1)
Expand Down
2 changes: 1 addition & 1 deletion construct/proxy/qunit.html
Expand Up @@ -15,7 +15,7 @@ <h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-test-area"></div>
<script type='text/javascript'>
steal('funcunit/qunit','can/construct/proxy').then('can/construct/proxy/proxy_test.js')
steal('funcunit/qunit').then('can/construct/proxy/proxy_test.js')
</script>
</body>
</html>

0 comments on commit b558c9b

Please sign in to comment.