Skip to content

Commit

Permalink
fix: <fixed issue: uku-repest=num in 100 doesn't work>
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake.Zheng authored and Jake.Zheng committed Sep 23, 2018
1 parent 7cfbc7e commit 2d72846
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 40 deletions.
12 changes: 12 additions & 0 deletions demo/components/comp7.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<uku-component>
<template>
<ul>
<li uku-repeat="num in cc.totalNumber">
{{num}}
</li>
</ul>
</template>
<script>
this.totalNumber = 100;
</script>
</uku-component>
6 changes: 4 additions & 2 deletions demo/native.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@

<body uku-application>
<!-- <my-comp5 uku-item-value="99 + myCtrl.number" uku-item-value2="myCtrl.show"></my-comp5> -->
<my-comp6 id="comp6" uku-current-state="myCtrl.loginState"></my-comp6>
<!-- <my-comp6 id="comp6" uku-current-state="myCtrl.loginState"></my-comp6> -->
<my-comp7></my-comp7>
<button uku-onclick="myCtrl.switchState()">change state</button>
</body>
<script>
var uku = new Ukulele();
uku.registerController('myCtrl',new MyCtrl(uku));

//uku.registerComponent('my-comp5','components/comp5.html');
uku.registerComponent('my-comp6','components/comp6.html');
//uku.registerComponent('my-comp6','components/comp6.html');
uku.registerComponent('my-comp7','components/comp7.html');
uku.init();

function MyCtrl(uku){
Expand Down
2 changes: 1 addition & 1 deletion dist/uku.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/uku.js.map

Large diffs are not rendered by default.

18 changes: 0 additions & 18 deletions src/core/Analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,6 @@ export class Analyzer extends EventEmitter {
event['data'] = data;
cc._dom.dispatchEvent(event);
};
/* if(!cc.setState){
cc.setState = function(state){
cc._currentState = state;
self.uku.refresh(cc._alias);
}
Object.defineProperty(cc, 'currentState', {
set: function(value){
if(value){
cc._currentState = value;
self.uku.refresh(cc._alias);
}
},
get: function(){
return cc._currentState;
}
})
} */
this.uku.registerController(randomAlias, cc);
for (let i = 0; i < attrs.length; i++) {
let attr = attrs[i];
Expand Down
9 changes: 9 additions & 0 deletions src/model/BoundItemRepeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ export class BoundItemRepeat extends BoundItemBase{
if (!finalValue) {
return;
}
if(typeof finalValue === "number" && Math.floor(finalValue) === finalValue){
//finalValue =
let newFinalValue = [];
for(let num=1; num <= finalValue; num++){
//let item = {value: num};
newFinalValue.push(num);
}
finalValue = newFinalValue;
}

let self = this;
if (this.element && this.element.parentNode) {
Expand Down
32 changes: 14 additions & 18 deletions src/util/UkuleleUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ export class UkuleleUtil {

});
var result;
try{
try {
result = eval(attrName);
}catch(err){
} catch (err) {
result = '';
}
tempScope = null;
Expand All @@ -166,15 +166,15 @@ export class UkuleleUtil {
static setFinalValue(object: Object, attrName: string, value: any) {
return (function () {
var tempScope = {};
attrName = attrName.replace('parent.','');
attrName = attrName.replace('parent.', '');
tempScope[object['_alias']] = object;

let valueString;
if(typeof value === "string"){
if (typeof value === "string") {
valueString = '"' + value + '"';
}else if(typeof value === "object"){
} else if (typeof value === "object") {
valueString = "JSON.parse('" + JSON.stringify(value) + "')";
}else{
} else {
valueString = value;
}

Expand All @@ -183,13 +183,12 @@ export class UkuleleUtil {
})();
}

static wrapScriptInComponent(originalScript):string{
if(originalScript){
let trimScript = originalScript.replace(new RegExp('\\s', 'gm'),'');
if(trimScript.search(new RegExp('\\(function\\(')) === 0){
return originalScript;
}else{
let selfExcutingFrame =
static wrapScriptInComponent(originalScript): string {
let trimScript = originalScript.replace(new RegExp('\\s', 'gm'), '');
if (trimScript.search(new RegExp('\\(function\\(')) === 0) {
return originalScript;
} else {
let selfExcutingFrame =
` (function(){
return function(uku){
Object.defineProperty(this, 'currentState', {
Expand All @@ -210,10 +209,7 @@ export class UkuleleUtil {
};
})();
`;
return selfExcutingFrame;
}
}else{
return "";
return selfExcutingFrame;
}
}
}

0 comments on commit 2d72846

Please sign in to comment.