Skip to content

Commit

Permalink
feat: <enhancement of script in component>
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake.Zheng authored and Jake.Zheng committed Sep 4, 2018
1 parent e387faf commit e32a0e0
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
1 change: 1 addition & 0 deletions demo/components/comp5.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
if(value !== undefined){
this.myItemValue2 = value;
console.log(this.myItemValue2);
console.log(uku);
}
}
})
Expand Down
16 changes: 16 additions & 0 deletions demo/components/comp6.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<uku-component>
<template>
<div>{{cc.a}}</div>
<div>{{cc.b}}</div>
<button uku-onclick="cc.sayHello()">click</button>
</template>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script>
this.a = 'a';
this.b = 'b';
this.sayHello = function(){
alert(uku);
alert($);
};
</script>
</uku-component>
7 changes: 2 additions & 5 deletions demo/native.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@
color:green;
}
</style>
<!-- <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> -->
<script src="../dist/uku.js"></script>
</head>

<body uku-application>
<my-comp5 uku-item-value="99 + myCtrl.number" uku-item-value2="myCtrl.show"></my-comp5>
<div>
{{999}}
</div>
<my-comp6></my-comp6>
</body>
<script>
var uku = new Ukulele();
Expand All @@ -27,7 +24,7 @@
//uku.registerComponent('my-comp3','components/comp3.html');
//uku.registerComponent('my-comp4','components/comp4.html');
uku.registerComponent('my-comp5','components/comp5.html');

uku.registerComponent('my-comp6','components/comp6.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.

1 change: 1 addition & 0 deletions src/core/DefinitionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export class DefinitionManager {
try {
let controllerClazz
if (script) {
script = UkuleleUtil.wrapScriptInComponent(script);
script += debugComment;
controllerClazz = eval(script);
}
Expand Down
20 changes: 20 additions & 0 deletions src/util/UkuleleUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,24 @@ export class UkuleleUtil {
eval(evalString);
})();
}

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 =
` (function(){
return function(uku){
${originalScript}
};
})();
`;
return selfExcutingFrame;
}
}else{
return "";
}
}
}

0 comments on commit e32a0e0

Please sign in to comment.