Skip to content

Commit 7b7802b

Browse files
Frank SchülerFrank Schüler
authored andcommitted
update
1 parent b5c65e3 commit 7b7802b

File tree

8 files changed

+171
-41
lines changed

8 files changed

+171
-41
lines changed

src/Application.js

Whitespace-only changes.

src/components/JsonData/index.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1-
import defineComponent from "../../utils/DefineComponentHelper";
1+
import { toNodeName, define } from "../../utils/DefineComponentHelper";
22
import Component from "../../Component";
33

4+
const NODENAME = toNodeName("json-data");
5+
46
class JsonData extends Component {
7+
8+
static get NODENAME() { return NODENAME; }
9+
510
constructor() {
611
super();
712
this.style.display = "none !important";
8-
this.__observer = new MutationObserver(() => {
9-
this.reinit();
10-
});
11-
observer.observe(this, { childList: true, characterData: true });
13+
this.__observer__ = new MutationObserver(() => { this.reinit(); });
14+
this.__observer__.observe(this, { childList: true, characterData: true });
1215
}
1316

14-
async init() {}
15-
async reinit() {delete this.__json;}
17+
async init() { }
18+
async reinit() { delete this.__json__; }
1619

1720
get json() {
18-
if(this.__json)
19-
this.__json = JSON.parse(this.textContent);
20-
21-
return this.__json;
21+
if (this.__json__)
22+
this.__json__ = JSON.parse(this.textContent);
23+
24+
return this.__json__;
2225
}
2326
}
2427

25-
defineComponent("json-data", JsonData);
28+
define(JsonData);
2629
export default Request;

src/components/Pagination/index.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import defineComponent from "../../utils/DefineComponentHelper";
1+
import { toNodeName, define } from "../../utils/DefineComponentHelper";
22
import { componentEventname } from "../../utils/EventHelper";
33
import { Renderer, Template } from "@default-js/defaultjs-template-language";
44
import { loadTemplate, ATTR_TEMPLATE } from "../../TemplateHelper";
55
import Component from "../../Component";
66

7-
const ATTR_PAGE = "page";
8-
const ATTR_COUNT = "count";
9-
const ATTR_SIZE = "size";
10-
const ATTR_DISABLED_SHADOW_DOM = "disabled-shadow-dom";
11-
const ATTR_DATA_PAGE = "data-page";
12-
const ATTRIBUTES = [ATTR_PAGE, ATTR_COUNT, ATTR_SIZE, ATTR_TEMPLATE];
7+
8+
const NODENAME = toNodeName("pagination");
9+
1310

1411
const TEMPLATE = Template.load(
1512
`
@@ -48,11 +45,20 @@ const toData = (page, count, size) => {
4845
return { start, end, pages, page, count, size };
4946
};
5047

48+
const ATTR_PAGE = "page";
49+
const ATTR_COUNT = "count";
50+
const ATTR_SIZE = "size";
51+
const ATTR_DISABLED_SHADOW_DOM = "disabled-shadow-dom";
52+
const ATTR_DATA_PAGE = "data-page";
53+
const ATTRIBUTES = [ATTR_PAGE, ATTR_COUNT, ATTR_SIZE, ATTR_TEMPLATE];
54+
5155
class Pagination extends Component {
5256
static get observedAttributes() {
5357
return ATTRIBUTES;
5458
}
5559

60+
static get NODENAME() { return NODENAME; }
61+
5662
constructor() {
5763
super();
5864
}
@@ -123,5 +129,5 @@ class Pagination extends Component {
123129
}
124130
}
125131

126-
defineComponent("pagination", Pagination);
132+
define(Pagination);
127133
export default Pagination;

src/components/Request/index.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1-
import defineComponent from "../../utils/DefineComponentHelper";
1+
import { toNodeName, define } from "../../utils/DefineComponentHelper";
22
import JsonData from "../JsonData";
3-
import {Requester} from "@default-js/defaultjs-dynamic-requester"
3+
import { Requester } from "@default-js/defaultjs-dynamic-requester"
44

5+
6+
const NODENAME = toNodeName("request");
57
class Request extends JsonData {
68
constructor() {
79
super();
810
this.style.display = "none !important";
911
}
1012

1113
async reinit() {
12-
delete this.__json;
13-
delete this.__requester;
14+
delete this.__json__;
15+
delete this.__requester__;
1416
}
1517

1618
get request() {
1719
return this.json;
1820
}
1921

20-
get requester(){
21-
if(this.__requester)
22-
this.__requester = new Requester(this.request);
23-
24-
return this.__requester;
22+
get requester() {
23+
if (this.__requester__)
24+
this.__requester__ = new Requester(this.request);
25+
26+
return this.__requester__;
2527
}
2628

27-
async execute(context){
28-
return this.requester.execute({context});
29+
async execute(context) {
30+
return this.requester.execute({ context });
2931
}
3032

3133
}
3234

33-
defineComponent("request", Request);
35+
define(Request);
3436
export default Request;

src/components/Route/index.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { toNodeName, define } from "../../utils/DefineComponentHelper";
2+
import { componentEventname } from "../../utils/EventHelper";
3+
import { Renderer, Template } from "@default-js/defaultjs-template-language";
4+
import { loadTemplate, ATTR_TEMPLATE } from "../../TemplateHelper";
5+
import Component from "../../Component";
6+
7+
const NODENAME = toNodeName("route");
8+
9+
10+
export const ATTR_ACTIVE = "active";
11+
export const ATTR_COMPONENT_TAG = "component-tag";
12+
export const ATTR_COMPONENT_TAG_ATTRIBUTES = "tag-attributes";
13+
export const ATTR_INIT_PARAMS = "init-params"
14+
const ATTRIBUTES = [ATTR_COMPONENT, ATTR_TAG_ATTRIBUTES, ATTR_INIT_PARAMS];
15+
16+
const EVENT_ACTIVATE = NODENAME + "-activate";
17+
const EVENT_DEACTIVATE = NODENAME + "-deactivate";
18+
const EVENTS = [EVENT_ACTIVATE, EVENT_DEACTIVATE];
19+
20+
21+
const getInitParams = (route) => {
22+
23+
}
24+
25+
const getAppContext = (route) => {
26+
27+
let node = route.parent();
28+
let app = null;
29+
while(node != null){
30+
31+
if(node instanceof Router)
32+
}
33+
34+
35+
}
36+
37+
38+
class Route extends Component {
39+
static get observedAttributes() {
40+
return ATTRIBUTES;
41+
}
42+
43+
static get NODENAME() { return NODENAME; }
44+
45+
static get EVENTS() { return EVENTS; }
46+
47+
constructor() {
48+
super();
49+
}
50+
51+
async init() {
52+
}
53+
54+
get active() {
55+
return this.hasAttribute(ATTR_ACTIVE);
56+
}
57+
58+
set active(active) {
59+
const current = this.active;
60+
if (active != current) {
61+
this.attr(ATTR_ACTIVE, active ? "" : null);
62+
if (active) {
63+
this.trigger(EVENT_ACTIVATE);
64+
} else {
65+
this.trigger(EVENT_DEACTIVATE);
66+
delete this.__component__;
67+
}
68+
69+
}
70+
}
71+
72+
get component() {
73+
if (!this.__component__) {
74+
const type = this.attr(ATTR_TAG)
75+
customElements.get()
76+
}
77+
return this.__component__;
78+
}
79+
}
80+
81+
define(Route);
82+
export default Route;

src/components/Router/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { toNodeName, define } from "../../utils/DefineComponentHelper";
2+
import { componentEventname } from "../../utils/EventHelper";
3+
import { Renderer, Template } from "@default-js/defaultjs-template-language";
4+
import { loadTemplate, ATTR_TEMPLATE } from "../../TemplateHelper";
5+
import Component from "../../Component";
6+
7+
8+
const NODENAME = toNodeName("router");
9+
class Router extends Component {
10+
static get NODENAME() { return NODENAME; }
11+
12+
constructor() {
13+
super();
14+
}
15+
16+
async init() {
17+
18+
}
19+
}
20+
21+
define(Router);
22+
export default Router;

src/components/Typeahead/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
import defineComponent from "../../utils/DefineComponentHelper";
1+
import { toNodeName, define } from "../../utils/DefineComponentHelper";
22
import { componentEventname } from "../../utils/EventHelper";
33
import { Renderer, Template } from "@default-js/defaultjs-template-language";
44
import { loadTemplate, ATTR_TEMPLATE } from "../../TemplateHelper";
55
import Component from "../../Component";
66

7+
8+
const NODENAME = toNodeName("typeahead");
79
const ATTRIBUTES = [ATTR_TEMPLATE];
810

911
const TEMPLATE = create(`
1012
<jstl foreach="\${items}">
1113
<option value="\${item.key}">\${item.title}</option>
12-
</jstl>`,true);
14+
</jstl>`, true);
1315

1416
class Typeahead extends Component {
1517
static get observedAttributes() {
1618
return ATTRIBUTES;
1719
}
1820

21+
static get NODENAME() { return NODENAME; }
22+
1923
constructor() {
2024
super();
2125
}
2226

23-
async init() {
27+
async init() {
2428
const template = await loadTemplate(this, TEMPLATE);
2529
this.__root__ = this;
2630
if (!this.disabledShadowDom && template != TEMPLATE) {
@@ -40,10 +44,10 @@ class Typeahead extends Component {
4044
return this.hasAttribute(ATTR_DISABLED_SHADOW_DOM);
4145
}
4246

43-
async render() {
47+
async render() {
4448
this.renderer.render({ data, container: this.__root__ });
4549
}
4650
}
4751

48-
defineComponent("typeahead", Typeahead);
52+
define(Typeahead);
4953
export default Typeahead;

src/utils/DefineComponentHelper.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import { componentPrefix } from "../Constants";
2-
export default (name, clazz, options) => {
3-
const componentName = componentPrefix + name;
4-
if (!customElements.get(componentName)) {
5-
customElements.define(componentName, clazz, options);
2+
3+
export const toNodeName = (name, prefix) => {
4+
if(typeof prefix === "string")
5+
return prefix + name;
6+
7+
return componentPrefix + name;
8+
};
9+
10+
export const define = function(clazz, options) {
11+
const nodename = clazz.NODENAME;
12+
if (!customElements.get(nodename)) {
13+
customElements.define(nodename, clazz, options);
614
}
715
};
16+
17+
18+
export default define;

0 commit comments

Comments
 (0)