Skip to content

Commit 4afb2ab

Browse files
committed
break down into unix like functions
1 parent c89a988 commit 4afb2ab

12 files changed

+104
-116
lines changed

$hell.js

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

$hell.js.map

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

$hell.ts

+9-59
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import {getChildFromSinglePath} from './getChildFromSinglePath.js';
2+
import {cd} from './cd.js';
3+
import {dashToCamelCase} from './dashToCamelCase.js';
4+
15
class $hell{
2-
static DASH_TO_CAMEL = /-[a-z]/g;
36

4-
static dashToCamelCase(dash) {
5-
return dash.replace($hell.DASH_TO_CAMEL, m =>m[1].toUpperCase());
6-
}
77
static $0: HTMLElement;
8-
static pathHistory: string[];
8+
static pathHistory: string[] = [];
99
static get pwd(){
1010
return this.pathHistory.join('/');
1111
}
@@ -16,62 +16,12 @@ class $hell{
1616
static cd(path: string){
1717
if(!this.$0 || path.startsWith('/')){
1818
this.initialize();
19-
}
20-
const splitPath = path.split('/');
21-
splitPath.forEach(token =>{
22-
if(!token) return;
23-
this.pathHistory.push(token);
24-
// let idx = 0;
25-
// let nonIndexedToken = token;
26-
// if(token === '..'){
27-
// this.$0 = this.$0.parentElement;
28-
// //if(typeof $0 !== 'undefined') $0 = this.currentEl;
29-
// return this.$0;
30-
// }else if(token.endsWith(']')){
31-
// const posOfOpen = token.indexOf('[');
32-
// const indxString = token.substring(posOfOpen + 1, token.length - 1);
33-
// idx = parseInt(indxString);
34-
// nonIndexedToken = token.substring(0, posOfOpen);
35-
// }
36-
// //const children = this.$0.querySelectorAll(':scope > ' + nonIndexedToken);
37-
// const matchingNodes = [];
38-
// this.children.forEach((child : HTMLElement) =>{
39-
// if(child.matches && child.matches(nonIndexedToken)){
40-
// matchingNodes.push(child);
41-
// }
42-
// })
43-
44-
//this.$0 = matchingNodes[idx] as HTMLElement;
45-
this.$0 = this.getChildFromSinglePath(this.$0, token);
46-
47-
})
19+
}
20+
this.$0 = cd(this.$0, path, this.pathHistory);
4821
return this.$0;
4922
}
5023

51-
static getChildFromSinglePath(el: HTMLElement, token: string){
52-
let idx = 0;
53-
let nonIndexedToken = token;
54-
if(token === '..'){
55-
// this.$0 = this.$0.parentElement;
56-
// return this.$0;
57-
return e.parentNode;
58-
}
59-
if(token.endsWith(']')){
60-
const posOfOpen = token.indexOf('[');
61-
const indxString = token.substring(posOfOpen + 1, token.length - 1);
62-
idx = parseInt(indxString);
63-
nonIndexedToken = token.substring(0, posOfOpen);
64-
}
65-
//const children = this.$0.querySelectorAll(':scope > ' + nonIndexedToken);
66-
const matchingNodes = [];
67-
this.getChildren(el).forEach((child : HTMLElement) =>{
68-
if(child.matches && child.matches(nonIndexedToken)){
69-
matchingNodes.push(child);
70-
}
71-
})
7224

73-
return matchingNodes[idx] as HTMLElement;
74-
}
7525
static getChildren(parent: HTMLElement){
7626
switch(parent.nodeName){
7727
case 'IFRAME':
@@ -159,7 +109,7 @@ class $hell{
159109
const observedAttributes = ce['observedAttributes'] as string[];
160110
if(observedAttributes){
161111
observedAttributes.forEach(attrib =>{
162-
const camelCase = this.dashToCamelCase(attrib);
112+
const camelCase = dashToCamelCase(attrib);
163113
props[camelCase] = true;
164114
})
165115
}
@@ -197,7 +147,7 @@ class $hell{
197147
const list = this.getList(this.getChildren(parent));
198148
let path = '';
199149
list.forEach(token =>{
200-
const testEl = this.getChildFromSinglePath(parent, token);
150+
const testEl = getChildFromSinglePath(parent, token);
201151
if(testEl === el){
202152
path = token;
203153
}

cd.js

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

0 commit comments

Comments
 (0)