Skip to content

Commit

Permalink
merging with #1632 and making can.proxy work faster
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbmeyer committed May 18, 2015
2 parents 6e42473 + 773856e commit f499ec4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 34 deletions.
14 changes: 13 additions & 1 deletion util/can.js
Expand Up @@ -40,7 +40,19 @@ steal(function () {
can.last = function(arr){
return arr && arr[arr.length - 1];
};

var protoBind = Function.prototype.bind;
if(protoBind) {
can.proxy = function(fn, context){
return protoBind.apply(fn, context);
};
} else {
can.proxy = function (fn, context) {
return function () {
return fn.apply(context, arguments);
};
};
}


can.frag = function(item){
var frag;
Expand Down
6 changes: 1 addition & 5 deletions util/jquery/jquery.js
Expand Up @@ -95,11 +95,7 @@ steal('jquery', 'can/util/can.js', 'can/util/attr', "can/event", 'can/util/array
}
return this;
},
proxy: function (fn, context) {
return function () {
return fn.apply(context, arguments);
};
},
proxy: can.proxy,
attr: attr
});
// Wrap binding functions.
Expand Down
7 changes: 0 additions & 7 deletions util/mootools/mootools.js
Expand Up @@ -103,13 +103,6 @@ steal('can/util/can.js', 'can/util/attr', 'mootools', 'can/event', 'can/util/fra
return Object.keys(object)
.length === 0;
};
var k = function(){};
// Map function helpers.
can.proxy = function () {
var args = can.makeArray(arguments),
func = args.shift();
return k.bind.apply(func, args);
};
can.isFunction = function (f) {
return typeOf(f) === 'function';
};
Expand Down
6 changes: 0 additions & 6 deletions util/zepto/zepto.js
Expand Up @@ -180,12 +180,6 @@ steal('can/util/can.js', 'can/util/attr', 'can/event', 'zepto', 'can/util/object
return ret;
};

can.proxy = function (f, ctx) {
return function () {
return f.apply(ctx, arguments);
};
};

// Make ajax.
var XHR = $.ajaxSettings.xhr;
$.ajaxSettings.xhr = function () {
Expand Down
22 changes: 7 additions & 15 deletions view/stache/doc/helpers/data.md
@@ -1,6 +1,6 @@
@function can.stache.helpers.data {{data name}}
@parent can.stache.htags 7
@signature `{{data name}}`
@signature `{{data name[ key]}}`

Adds the current [can.stache.context context] to the
element's [can.data].
Expand All @@ -12,23 +12,15 @@ context.

## Use

It is common for you to want some data in the template to be available
It is common to want some data in the template to be available
on an element. `{{data name}}` allows you to save the
context so it can later be retrieved by [can.data] or
`$.fn.data`. For example,
`$.fn.data`.

The template:
<a class="jsbin-embed" href="http://jsbin.com/juxem/7/embed?html,js,output">JS Bin</a><script src="http://static.jsbin.com/js/embed.js"></script>

<ul>
<li id="person" {{data 'person'}}>{{name}}</li>
</ul>
### Getting more specific

Rendered with:

document.body.appendChild(
can.stache(template,{ person: { name: 'Austin' } });

Retrieve the person data back with:

$("#person").data("person")
By passing a key name as the second argument to the data helper, you can specify which data is used: `{{data name key}}`.

<a class="jsbin-embed" href="http://jsbin.com/munuco/1/embed?html,js,output">JS Bin</a><script src="http://static.jsbin.com/js/embed.js"></script>

0 comments on commit f499ec4

Please sign in to comment.