Skip to content

Commit a190770

Browse files
committed
release v0.5.2
1 parent 903117a commit a190770

File tree

4 files changed

+70
-47
lines changed

4 files changed

+70
-47
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "regularjs",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"main": "dist/regular.js",
55
"description": "reactjs + angularjs = regularjs",
66
"authors": "@leeluolee <87399126@163.com>",

dist/regular.js

+65-42
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
@author leeluolee
3-
@version 0.5.1
3+
@version 0.5.2
44
@homepage http://regularjs.github.io
55
*/
66
(function webpackUniversalModuleDefinition(root, factory) {
@@ -147,6 +147,12 @@ return /******/ (function(modules) { // webpackBootstrap
147147
return res;
148148
}
149149

150+
_.some = function(list, fn){
151+
for(var i =0,len = list.length; i < len; i++){
152+
if(fn(list[i])) return true
153+
}
154+
}
155+
150156
_.varName = 'd';
151157
_.setName = 'p_';
152158
_.ctxName = 'c';
@@ -176,7 +182,7 @@ return /******/ (function(modules) { // webpackBootstrap
176182

177183
// beacuse slice and toLowerCase is expensive. we handle undefined and null in another way
178184
_.typeOf = function (o) {
179-
return o == null ? String(o) :o2str.call(o).slice(8, -1);
185+
return o == null ? String(o) :o2str.call(o).slice(8, -1).toLowerCase();
180186
}
181187

182188

@@ -528,9 +534,9 @@ return /******/ (function(modules) { // webpackBootstrap
528534
_.normListener = function( events ){
529535
var eventListeners = [];
530536
var pType = _.typeOf( events );
531-
if( pType === 'Array' ){
537+
if( pType === 'array' ){
532538
return events;
533-
}else if ( pType === 'Object' ){
539+
}else if ( pType === 'object' ){
534540
for( var i in events ) if ( events.hasOwnProperty(i) ){
535541
eventListeners.push({
536542
type: i,
@@ -1663,13 +1669,13 @@ return /******/ (function(modules) { // webpackBootstrap
16631669
*/
16641670
$bind: function(component, expr1, expr2){
16651671
var type = _.typeOf(expr1);
1666-
if( expr1.type === 'expression' || type === 'String' ){
1672+
if( expr1.type === 'expression' || type === 'string' ){
16671673
this._bind(component, expr1, expr2)
1668-
}else if( type === "Array" ){ // multiply same path binding through array
1674+
}else if( type === "array" ){ // multiply same path binding through array
16691675
for(var i = 0, len = expr1.length; i < len; i++){
16701676
this._bind(component, expr1[i]);
16711677
}
1672-
}else if(type === "Object"){
1678+
}else if(type === "object"){
16731679
for(var i in expr1) if(expr1.hasOwnProperty(i)){
16741680
this._bind(component, i, expr1[i]);
16751681
}
@@ -1783,11 +1789,15 @@ return /******/ (function(modules) { // webpackBootstrap
17831789

17841790
if(expr.setbody && !expr.set){
17851791
var setbody = expr.setbody;
1786-
expr.set = function(ctx, value, ext){
1787-
expr.set = new Function(_.ctxName, _.setName , _.extName, _.prefix + setbody);
1788-
return expr.set(ctx, value, ext);
1792+
var filters = expr.filters;
1793+
var self = this;
1794+
if(!filters || !_.some(filters, function(filter){ return !self._f_(filter).set }) ){
1795+
expr.set = function(ctx, value, ext){
1796+
expr.set = new Function(_.ctxName, _.setName , _.extName, _.prefix + setbody);
1797+
return expr.set(ctx, value, ext);
1798+
}
17891799
}
1790-
expr.setbody = null;
1800+
expr.filters = expr.setbody = null;
17911801
}
17921802
if(expr.set){
17931803
touched.set = !ext? expr.set : function(ctx, value){
@@ -2131,7 +2141,7 @@ return /******/ (function(modules) { // webpackBootstrap
21312141
if(typeof handler === 'string'){
21322142
handler = wrapHander(handler);
21332143
}
2134-
if(_.typeOf(reg) === 'RegExp') reg = reg.toString().slice(1, -1);
2144+
if(_.typeOf(reg) === 'regexp') reg = reg.toString().slice(1, -1);
21352145

21362146
reg = reg.replace(/\{(\w+)\}/g, replaceFn)
21372147
retain = _.findSubCapture(reg) + 1;
@@ -2629,7 +2639,7 @@ return /******/ (function(modules) { // webpackBootstrap
26292639

26302640
var body = buffer.get || buffer;
26312641
var setbody = buffer.set;
2632-
return node.expression(body, setbody, !this.depend.length);
2642+
return node.expression(body, setbody, !this.depend.length, buffer.filters);
26332643
}
26342644

26352645

@@ -2638,25 +2648,34 @@ return /******/ (function(modules) { // webpackBootstrap
26382648
op.filter = function(){
26392649
var left = this.assign();
26402650
var ll = this.eat('|');
2641-
var buffer = [], setBuffer, prefix,
2651+
var buffer = [], filters,setBuffer, prefix,
26422652
attr = "t",
26432653
set = left.set, get,
26442654
tmp = "";
26452655

26462656
if(ll){
2647-
if(set) setBuffer = [];
2657+
if(set) {
2658+
setBuffer = [];
2659+
filters = [];
2660+
}
26482661

26492662
prefix = "(function(" + attr + "){";
26502663

26512664
do{
2652-
tmp = attr + " = " + ctxName + "._f_('" + this.match('IDENT').value+ "' ).get.call( "+_.ctxName +"," + attr ;
2665+
var filterName = this.match('IDENT').value;
2666+
tmp = attr + " = " + ctxName + "._f_('" + filterName + "' ).get.call( "+_.ctxName +"," + attr ;
26532667
if(this.eat(':')){
26542668
tmp +=", "+ this.arguments("|").join(",") + ");"
26552669
}else{
26562670
tmp += ');'
26572671
}
26582672
buffer.push(tmp);
2659-
setBuffer && setBuffer.unshift( tmp.replace(" ).get.call", " ).set.call") );
2673+
2674+
if(set){
2675+
// only in runtime ,we can detect whether the filter has a set function.
2676+
filters.push(filterName);
2677+
setBuffer.unshift( tmp.replace(" ).get.call", " ).set.call") );
2678+
}
26602679

26612680
}while(ll = this.eat('|'));
26622681
buffer.push("return " + attr );
@@ -2671,7 +2690,9 @@ return /******/ (function(modules) { // webpackBootstrap
26712690

26722691
}
26732692
// the set function is depend on the filter definition. if it have set method, the set will work
2674-
return this.getset(get, set);
2693+
var ret = getset(get, set);
2694+
ret.filters = filters;
2695+
return ret;
26752696
}
26762697
return left;
26772698
}
@@ -2682,8 +2703,8 @@ return /******/ (function(modules) { // webpackBootstrap
26822703
var left = this.condition(), ll;
26832704
if(ll = this.eat(['=', '+=', '-=', '*=', '/=', '%='])){
26842705
if(!left.set) this.error('invalid lefthand expression in assignment expression');
2685-
return this.getset( left.set.replace( "," + _.setName, "," + this.condition().get ).replace("'='", "'"+ll.type+"'"), left.set);
2686-
// return this.getset('(' + left.get + ll.type + this.condition().get + ')', left.set);
2706+
return getset( left.set.replace( "," + _.setName, "," + this.condition().get ).replace("'='", "'"+ll.type+"'"), left.set);
2707+
// return getset('(' + left.get + ll.type + this.condition().get + ')', left.set);
26872708
}
26882709
return left;
26892710
}
@@ -2694,7 +2715,7 @@ return /******/ (function(modules) { // webpackBootstrap
26942715

26952716
var test = this.or();
26962717
if(this.eat('?')){
2697-
return this.getset([test.get + "?",
2718+
return getset([test.get + "?",
26982719
this.assign().get,
26992720
this.match(":").type,
27002721
this.assign().get].join(""));
@@ -2710,7 +2731,7 @@ return /******/ (function(modules) { // webpackBootstrap
27102731
var left = this.and();
27112732

27122733
if(this.eat('||')){
2713-
return this.getset(left.get + '||' + this.or().get);
2734+
return getset(left.get + '||' + this.or().get);
27142735
}
27152736

27162737
return left;
@@ -2722,7 +2743,7 @@ return /******/ (function(modules) { // webpackBootstrap
27222743
var left = this.equal();
27232744

27242745
if(this.eat('&&')){
2725-
return this.getset(left.get + '&&' + this.and().get);
2746+
return getset(left.get + '&&' + this.and().get);
27262747
}
27272748
return left;
27282749
}
@@ -2736,7 +2757,7 @@ return /******/ (function(modules) { // webpackBootstrap
27362757
var left = this.relation(), ll;
27372758
// @perf;
27382759
if( ll = this.eat(['==','!=', '===', '!=='])){
2739-
return this.getset(left.get + ll.type + this.equal().get);
2760+
return getset(left.get + ll.type + this.equal().get);
27402761
}
27412762
return left
27422763
}
@@ -2749,7 +2770,7 @@ return /******/ (function(modules) { // webpackBootstrap
27492770
var left = this.additive(), ll;
27502771
// @perf
27512772
if(ll = (this.eat(['<', '>', '>=', '<=']) || this.eat('IDENT', 'in') )){
2752-
return this.getset(left.get + ll.value + this.relation().get);
2773+
return getset(left.get + ll.value + this.relation().get);
27532774
}
27542775
return left
27552776
}
@@ -2760,7 +2781,7 @@ return /******/ (function(modules) { // webpackBootstrap
27602781
op.additive = function(){
27612782
var left = this.multive() ,ll;
27622783
if(ll= this.eat(['+','-']) ){
2763-
return this.getset(left.get + ll.value + this.additive().get);
2784+
return getset(left.get + ll.value + this.additive().get);
27642785
}
27652786
return left
27662787
}
@@ -2772,7 +2793,7 @@ return /******/ (function(modules) { // webpackBootstrap
27722793
op.multive = function(){
27732794
var left = this.range() ,ll;
27742795
if( ll = this.eat(['*', '/' ,'%']) ){
2775-
return this.getset(left.get + ll.type + this.multive().get);
2796+
return getset(left.get + ll.type + this.multive().get);
27762797
}
27772798
return left;
27782799
}
@@ -2784,7 +2805,7 @@ return /******/ (function(modules) { // webpackBootstrap
27842805
right = this.unary();
27852806
var body =
27862807
"(function(start,end){var res = [],step=end>start?1:-1; for(var i = start; end>start?i <= end: i>=end; i=i+step){res.push(i); } return res })("+left.get+","+right.get+")"
2787-
return this.getset(body);
2808+
return getset(body);
27882809
}
27892810

27902811
return left;
@@ -2800,7 +2821,7 @@ return /******/ (function(modules) { // webpackBootstrap
28002821
op.unary = function(){
28012822
var ll;
28022823
if(ll = this.eat(['+','-','~', '!'])){
2803-
return this.getset('(' + ll.type + this.unary().get + ')') ;
2824+
return getset('(' + ll.type + this.unary().get + ')') ;
28042825
}else{
28052826
return this.member()
28062827
}
@@ -2926,14 +2947,14 @@ return /******/ (function(modules) { // webpackBootstrap
29262947
this.next();
29272948
var value = "" + ll.value;
29282949
var quota = ~value.indexOf("'")? "\"": "'" ;
2929-
return this.getset(quota + value + quota);
2950+
return getset(quota + value + quota);
29302951
case 'NUMBER':
29312952
this.next();
2932-
return this.getset( "" + ll.value );
2953+
return getset( "" + ll.value );
29332954
case "IDENT":
29342955
this.next();
29352956
if(isKeyWord(ll.value)){
2936-
return this.getset( ll.value );
2957+
return getset( ll.value );
29372958
}
29382959
return ll.value;
29392960
default:
@@ -2990,11 +3011,12 @@ return /******/ (function(modules) { // webpackBootstrap
29903011
this.match('(');
29913012
var res = this.filter()
29923013
res.get = '(' + res.get + ')';
3014+
res.set = res.set;
29933015
this.match(')');
29943016
return res;
29953017
}
29963018

2997-
op.getset = function(get, set){
3019+
function getset(get, set){
29983020
return {
29993021
get: get,
30003022
set: set
@@ -3045,12 +3067,13 @@ return /******/ (function(modules) { // webpackBootstrap
30453067
track: track
30463068
}
30473069
},
3048-
expression: function( body, setbody, constant ){
3070+
expression: function( body, setbody, constant, filters ){
30493071
return {
30503072
type: "expression",
30513073
body: body,
30523074
constant: constant || false,
3053-
setbody: setbody || false
3075+
setbody: setbody || false,
3076+
filters: filters
30543077
}
30553078
},
30563079
text: function(text){
@@ -3772,7 +3795,7 @@ return /******/ (function(modules) { // webpackBootstrap
37723795
if(altGroup.destroy) altGroup.destroy(true);
37733796
}
37743797

3775-
if( nType === 'Object' ) rawNewValue = newValue;
3798+
if( nType === 'object' ) rawNewValue = newValue;
37763799

37773800
if(track === true){
37783801
updateSimple( newList, oldList, rawNewValue );
@@ -3835,7 +3858,7 @@ return /******/ (function(modules) { // webpackBootstrap
38353858
};
38363859

38373860
function getListFromValue(value, type){
3838-
return type === 'Array'? value: (type === 'Object'? _.keys(value) : []);
3861+
return type === 'array'? value: (type === 'object'? _.keys(value) : []);
38393862
}
38403863

38413864

@@ -5004,7 +5027,7 @@ return /******/ (function(modules) { // webpackBootstrap
50045027
// stable watch is dirty
50055028
var stableDirty = this._digest(true);
50065029

5007-
if( n > 0 && stableDirty && this.$emit) {
5030+
if( (n > 0 || stableDirty) && this.$emit) {
50085031
this.$emit("$update");
50095032
if (this.devtools) {
50105033
this.devtools.emit("flush", this)
@@ -5069,11 +5092,11 @@ return /******/ (function(modules) { // webpackBootstrap
50695092
eq = true;
50705093

50715094
// !Object
5072-
if( !(tnow === 'Object' && tlast==='Object' && watcher.deep) ){
5095+
if( !(tnow === 'object' && tlast==='object' && watcher.deep) ){
50735096
// Array
5074-
if( tnow === 'Array' && ( tlast=='undefined' || tlast === 'Array') ){
5097+
if( tnow === 'array' && ( tlast=='undefined' || tlast === 'array') ){
50755098
diff = diffArray(now, watcher.last || [], watcher.diff)
5076-
if( tlast !== 'Array' || diff === true || diff.length ) dirty = true;
5099+
if( tlast !== 'array' || diff === true || diff.length ) dirty = true;
50775100
}else{
50785101
eq = _.equals( now, last );
50795102
if( !eq || watcher.force ){
@@ -5096,7 +5119,7 @@ return /******/ (function(modules) { // webpackBootstrap
50965119
}
50975120
}
50985121
if(dirty && !watcher.test){
5099-
if(tnow === 'Object' && watcher.deep || tnow === 'Array'){
5122+
if(tnow === 'object' && watcher.deep || tnow === 'array'){
51005123
watcher.last = _.clone(now);
51015124
}else{
51025125
watcher.last = now;

dist/regular.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "regularjs",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"author": {
55
"name": "leeluolee"
66
},

0 commit comments

Comments
 (0)