Skip to content

Commit 69abb8d

Browse files
committed
fixed visibility error
1 parent ba0e609 commit 69abb8d

File tree

7 files changed

+174
-30
lines changed

7 files changed

+174
-30
lines changed

OpenScript.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,12 +2203,30 @@ var OpenScript = {
22032203

22042204
k = k.replace(/_/g, "-");
22052205

2206-
if(k === "class" || k === "Class") val = root.getAttribute(k) ?? "" + ` ${val}`;
2206+
if(k === "class" || k === "Class"){
2207+
val = (root.getAttribute(k) ?? "") + ` ${val}`;
2208+
}
22072209

22082210
root.setAttribute(k, val);
22092211
}
22102212
}
22112213

2214+
const parse = (arg, isComp) => {
2215+
if(arg instanceof DocumentFragment || arg instanceof HTMLElement) {
2216+
if(isComp) return true;
2217+
2218+
rootFrag.append(arg);
2219+
return true;
2220+
}
2221+
2222+
if(typeof arg === "object") {
2223+
parseAttr(arg);
2224+
return true;
2225+
}
2226+
2227+
return false;
2228+
}
2229+
22122230

22132231
for(let arg of args) {
22142232

@@ -2217,24 +2235,17 @@ var OpenScript = {
22172235
if(arg instanceof OpenScript.State) continue;
22182236

22192237
if(Array.isArray(arg)) {
2238+
22202239
if(isComponent) continue;
2221-
arg.forEach(e => {
2222-
if(e) rootFrag.append(this.toElement(e));
2240+
2241+
arg.forEach(e => {
2242+
if(e) parse(e, isComponent);
22232243
});
2224-
continue;
2225-
}
2226-
2227-
if(arg instanceof DocumentFragment || arg instanceof HTMLElement) {
2228-
if(isComponent) continue;
22292244

2230-
rootFrag.append(arg);
2231-
continue;
2232-
}
2233-
2234-
if(typeof arg === "object") {
2235-
parseAttr(arg);
22362245
continue;
22372246
}
2247+
2248+
if(parse(arg, isComponent)) continue;
22382249

22392250
if(isComponent) continue;
22402251

@@ -2261,7 +2272,7 @@ var OpenScript = {
22612272
parent.append(root);
22622273
}
22632274

2264-
checkComponentsVisibility();
2275+
// checkComponentsVisibility();
22652276

22662277
if(component){
22672278
component.emit(event, eventParams);
@@ -2297,7 +2308,7 @@ var OpenScript = {
22972308
* @param {function} f - This function should return an HTMLElement or a string or an Array of either
22982309
* @returns {HTMLElement|string|Array<HTMLElement|string>}
22992310
*/
2300-
call = (f = () => `<ojs-group></ojs-group>`) => {
2311+
call = (f = () => h['ojs-group']()) => {
23012312
return f();
23022313
}
23032314

example/components/App.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class App extends OpenScript.Component {
99
req("MainNav");
1010
req("Blog.List");
1111
req("Counter");
12+
req('Chart');
1213
}
1314

1415
render(...args) {
@@ -61,6 +62,10 @@ class App extends OpenScript.Component {
6162
h.BlogCounter(context("blogCxt").counter, {
6263
class: "p-1"
6364
}),
65+
66+
h.Chart(200, {
67+
class: "mb-3"
68+
}),
6469

6570
h.BlogList(context("blogCxt").blogs, context('blogCxt').counter, "I am a blog List. I re-render when counter changes"),
6671

example/components/Chart.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
class ProgressBar extends OpenScript.Component {
2+
3+
render(width, ...args){
4+
5+
return h.div(
6+
{
7+
class: "progress",
8+
role: "progressbar",
9+
aria_label: "Basic example",
10+
aria_valuenow: "0",
11+
aria_valuemin: "0",
12+
aria_valuemax: "100"
13+
},
14+
h.div( {
15+
class: "progress-bar",
16+
style: `width: ${width}%`
17+
}
18+
),
19+
...args
20+
)
21+
}
22+
23+
async $$numberChanged(){
24+
this.markup().forEach(element => {
25+
element.querySelector(".progress-bar").style.width = `${Math.floor(Math.random() * 100) % 100}%`;
26+
});
27+
}
28+
}
29+
30+
class Chart extends OpenScript.Component {
31+
32+
render(number, ...args) {
33+
34+
return h.div(
35+
{
36+
class: "card mb-3"
37+
},
38+
39+
h.div({class: 'card-header'}, `I am ${this.name} Component & I re-render`),
40+
41+
h.div(
42+
{ class: "card-body "},
43+
h.h4({ class: "card-text" }, "Highest: ", 200),
44+
h.call(() => {
45+
let bars = [];
46+
47+
for(let i = 0; i < 10; i++){
48+
let width = Math.floor(Math.random() * 100) % 100;
49+
bars.push(h.ProgressBar(width, {class: "mb-3"}))
50+
}
51+
52+
return bars;
53+
})
54+
),
55+
...args
56+
)
57+
}
58+
}

example/contexts/Root.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Root extends OpenScript.Context {
2+
3+
constructor() {
4+
super();
5+
this.test = state(1);
6+
}
7+
}

example/contexts/RootContext.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

example/logic.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ojs(async e => {
22

3-
fetchContext("rootCxt", "RootContext");
4-
fetchContext("blogCxt", "Blog.Context");
3+
fetchContext("rootCxt", "Root");
4+
putContext("blogCxt", "Blog.Context");
55

66
req("App");
77

@@ -25,6 +25,8 @@ ojs(async e => {
2525
bc.put("counter", state(0));
2626
bc.put("blogs", blog);
2727

28+
bc.number = state(0);
29+
2830
let rc = context("rootCxt");
2931
rc.domRoot = h.dom.querySelector("#root");
3032

@@ -51,5 +53,10 @@ ojs(async e => {
5153

5254
}, 1000);
5355

56+
setInterval(() => {
57+
bc.number.value++;
58+
broker.send('numberChanged')
59+
}, 500);
60+
5461
});
5562

example/ojs-config.js

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33
|----------------------------------
44
*/
55

6+
/**----------------------------------
7+
*
8+
* Set the default route path here
9+
* ----------------------------------
10+
*/
11+
route.basePath('example'); // === '/'
12+
613
/*-----------------------------------
714
| set the directories in which we
815
| can find the context files
916
|-----------------------------------
1017
*/
11-
ContextProvider.directory = './contexts';
18+
ContextProvider.directory = route.baseUrl('contexts');
1219

1320
/*-----------------------------------
1421
| set the version number of the
@@ -19,17 +26,75 @@ ContextProvider.directory = './contexts';
1926
*/
2027
ContextProvider.version = '1.0.0';
2128

29+
/*-----------------------------------
30+
| Set the Mediators directory
31+
| so that we an load the mediators
32+
| from that directory
33+
|-----------------------------------
34+
*/
35+
MediatorManager.directory = route.baseUrl('mediators');
36+
37+
/*-----------------------------------
38+
| Set the version number of the
39+
| mediator files so that we can
40+
| always load a fresh copy of the
41+
| mediators files upon changes.
42+
|----------------------------------
43+
*/
44+
MediatorManager.version = '1.0.0';
45+
2246
/*-----------------------------------
2347
| Set the default component
2448
| directory for the loader
2549
|-----------------------------------
2650
*/
27-
loader.dir = "./components";
51+
loader.dir = route.baseUrl('components');
2852

2953
/*-----------------------------------
3054
| set the version number of the
3155
| component files so that we load
3256
| a fresh file when they change
3357
|-----------------------------------
3458
*/
35-
loader.version = "1.0.0";
59+
loader.version = '1.0.0';
60+
61+
/*-----------------------------------
62+
| Set the default directory of the
63+
| autoload object for loading
64+
| files.
65+
|-----------------------------------
66+
*/
67+
68+
autoload.dir = route.baseUrl('classes');
69+
70+
/*-----------------------------------
71+
| set the version number of the
72+
| JS files so that we load
73+
| a fresh file when they change
74+
|-----------------------------------
75+
*/
76+
autoload.version = '1.0.0';
77+
78+
/*--------------------------------
79+
| Set the logs clearing interval
80+
| for the broker to remove stale
81+
| events. (milliseconds)
82+
|--------------------------------
83+
*/
84+
broker.CLEAR_LOGS_AFTER = 30000; // 30 secs
85+
86+
/*--------------------------------
87+
| Set how old an event must be
88+
| to be deleted from the broker's
89+
| event log during logs clearing
90+
|--------------------------------
91+
*/
92+
broker.TIME_TO_GC = 10000; // 10 secs
93+
94+
95+
/*-------------------------------------------
96+
| Start the garbage
97+
| collector for the broker
98+
|-------------------------------------------
99+
*/
100+
broker.removeStaleEvents(); // broker garbage collection started

0 commit comments

Comments
 (0)