-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: now extreme can render :for for custom component,but the perfor…
…mance is not good
- Loading branch information
Showing
15 changed files
with
239 additions
and
34 deletions.
There are no files selected for viewing
File renamed without changes.
9 changes: 8 additions & 1 deletion
9
apps/demo/src/components/my-button/index.ts → ...emo/src/components/blench/button/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./button" | ||
export * from './jumbotron' | ||
export * from './main' | ||
export * from './row' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import template from "./index.html?raw"; | ||
import { createComponent } from "@sourcebug/extreme/dev"; | ||
|
||
export const Jumbotron = createComponent<{ | ||
dispatch: (action: { type: string }) => void; | ||
}>("Jumbotron", ({ dispatch }) => { | ||
return { | ||
template, | ||
state: { | ||
run: () => dispatch({ type: "RUN" }), | ||
runLots: () => dispatch({ type: "RUN_LOTS" }), | ||
add: () => dispatch({ type: "ADD" }), | ||
update: () => dispatch({ type: "UPDATE" }), | ||
clear: () => dispatch({ type: "CLEAR" }), | ||
swapRows: () => dispatch({ type: "SWAP_ROWS" }), | ||
}, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div class="container"> | ||
<Jumbotron dispatch="{{dispatch}}" /> | ||
<table class="table table-hover table-striped test-data"> | ||
<tbody> | ||
<Row :for="item in data" key="{{item.id}}" item="{{item}}" dispatch="{{dispatch}}"></Row> | ||
</tbody> | ||
</table> | ||
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { createComponent, useState } from "@sourcebug/extreme/dev"; | ||
import template from "./index.html?raw"; | ||
|
||
const random = (max: number) => Math.round(Math.random() * 1000) % max; | ||
|
||
const A = [ | ||
"pretty", | ||
"large", | ||
"big", | ||
"small", | ||
"tall", | ||
"short", | ||
"long", | ||
"handsome", | ||
"plain", | ||
"quaint", | ||
"clean", | ||
"elegant", | ||
"easy", | ||
"angry", | ||
"crazy", | ||
"helpful", | ||
"mushy", | ||
"odd", | ||
"unsightly", | ||
"adorable", | ||
"important", | ||
"inexpensive", | ||
"cheap", | ||
"expensive", | ||
"fancy", | ||
]; | ||
const C = ["red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange"]; | ||
const N = [ | ||
"table", | ||
"chair", | ||
"house", | ||
"bbq", | ||
"desk", | ||
"car", | ||
"pony", | ||
"cookie", | ||
"sandwich", | ||
"burger", | ||
"pizza", | ||
"mouse", | ||
"keyboard", | ||
]; | ||
|
||
let nextId = 1; | ||
|
||
const buildData = (count: number) => { | ||
const data = new Array(count); | ||
|
||
for (let i = 0; i < count; i++) { | ||
data[i] = { | ||
id: nextId++, | ||
label: `${A[random(A.length)]} ${C[random(C.length)]} ${N[random(N.length)]}`, | ||
}; | ||
} | ||
|
||
return data; | ||
}; | ||
|
||
export const Main = createComponent("Main", () => { | ||
const [data, setData] = useState<any[]>([]); | ||
const [selected, setSelected] = useState(0); | ||
|
||
const dispatch = (action: { type: string; id: number }) => { | ||
switch (action.type) { | ||
case "RUN": | ||
debugger | ||
setData(buildData(1000)); | ||
setSelected(0); | ||
break; | ||
case "RUN_LOTS": | ||
setData(buildData(10000)); | ||
setSelected(0); | ||
break; | ||
case "ADD": | ||
setData(data().concat(buildData(1000))); | ||
break; | ||
case "UPDATE": { | ||
const newData = data().slice(0); | ||
for (let i = 0; i < newData.length; i += 10) { | ||
const r = newData[i]; | ||
newData[i] = { id: r.id, label: r.label + " !!!" }; | ||
} | ||
setData(newData); | ||
break; | ||
} | ||
case "CLEAR": | ||
setData([]); | ||
setSelected(0); | ||
break; | ||
case "SWAP_ROWS": | ||
const newdata = [...data()]; | ||
if (data().length > 998) { | ||
const d1 = newdata[1]; | ||
const d998 = newdata[998]; | ||
newdata[1] = d998; | ||
newdata[998] = d1; | ||
} | ||
setData(newdata); | ||
break; | ||
case "REMOVE": { | ||
const idx = data().findIndex((d) => d.id === action.id); | ||
setData([...data().slice(0, idx), ...data().slice(idx + 1)]); | ||
break; | ||
} | ||
case "SELECT": | ||
setSelected(action.id); | ||
break; | ||
default: | ||
break; | ||
} | ||
}; | ||
|
||
return { | ||
template, | ||
state: { | ||
data, | ||
selected, | ||
dispatch, | ||
}, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<tr class="{{containerClass}}"> | ||
<td class="col-md-1">{{item.id}}</td> | ||
<td class="col-md-4"> | ||
<a @click="{{handleSelect}}">{{item.label}}</a> | ||
</td> | ||
<td class="col-md-1"> | ||
<a @click="{{handleRemove}}"> | ||
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> | ||
</a> | ||
</td> | ||
<td class="col-md-6"></td> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createComponent } from "@sourcebug/extreme/dev"; | ||
import template from "./index.html?raw"; | ||
|
||
export const Row = createComponent<{ | ||
selected: number; | ||
item: { id: number; label: string }; | ||
dispatch: (action: { type: string; id: number }) => void; | ||
}>("Row", ({ selected, item, dispatch }) => { | ||
return { | ||
template, | ||
state: { | ||
item, | ||
// containerClass: () => (selected === item.id ? "danger" : ""), | ||
}, | ||
methods: { | ||
handleSelect: () => dispatch({ type: "SELECT", id: item.id }), | ||
handleRemove: () => dispatch({ type: "REMOVE", id: item.id }), | ||
}, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export * from "./counter" | ||
export * from "./list" | ||
export * from "./custom-component" | ||
export * from './my-button' | ||
export * from './jumbotron' | ||
export * from './blench' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters