Skip to content

Commit

Permalink
chore: code format
Browse files Browse the repository at this point in the history
  • Loading branch information
YUCLing committed Dec 17, 2024
1 parent cf2380e commit fcf70dd
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 144 deletions.
66 changes: 30 additions & 36 deletions framework/core/js/src/common/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,41 +357,37 @@ export default class Application {
let lastRoute: string;
let comp: Component | null = null;
function RoutedApp() {
return () => m.route(routePrefix, ({route}) => {
for (const k in routes) {
let match;
if (match = route.match(k)) {
const r = routes[k];
const { current, path, params } = route;
const routeData = {
current,
path,
params: match,
searchParams: params
};
appRef.routing = {
...route,
params: match,
searchParams: params
};
if (lastRoute != current) {
lastRoute = current;
r.onmatch(match, routeData).then((c: any) => {
comp = c;
this.redraw();
});
return () =>
m.route(routePrefix, ({ route }) => {
for (const k in routes) {
let match;
if ((match = route.match(k))) {
const r = routes[k];
const { current, path, params } = route;
const routeData = {
current,
path,
params: match,
searchParams: params,
};
appRef.routing = {
...route,
params: match,
searchParams: params,
};
if (lastRoute != current) {
lastRoute = current;
r.onmatch(match, routeData).then((c: any) => {
comp = c;
this.redraw();
});
}
return comp ? m.set({ appRoute: routeData }, r.render ? r.render(comp, match) : m(comp, match)) : m('div');
}
return comp ?
m.set({appRoute: routeData}, r.render ?
r.render(comp, match) :
m(comp, match)
) :
m('div');
}
}
});
});
}
this.redraw.app = m.mount(document.getElementById('content')!, () => <RoutedApp/>);
this.redraw.app = m.mount(document.getElementById('content')!, () => <RoutedApp />);

const appEl = document.getElementById('app')!;
const appHeaderEl = document.querySelector('.App-header')!;
Expand Down Expand Up @@ -551,10 +547,8 @@ export default class Application {
redrawAll(sync = false) {
for (const k in app.redraw) {
const redraw = app.redraw[k];
if (sync)
redraw.sync();
else
redraw();
if (sync) redraw.sync();
else redraw();
}
}

Expand Down
12 changes: 6 additions & 6 deletions framework/core/js/src/common/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import type Mithril from 'mithril';
export interface ComponentAttrs extends Mithril.Attributes {}

interface Redraw {
(): typeof m.redraw,
sync: typeof m.redraw.sync
(): typeof m.redraw;
sync: typeof m.redraw.sync;
}

interface Context {
redraw: Redraw,
[x: string]: any,
redraw: Redraw;
[x: string]: any;
}

export interface RenderAttrs<Attrs = {}, State = {}> {
attrs: Attrs
attrs: Attrs;
}

export interface RenderAttrsDOM<Attrs = {}, State = {}> extends RenderAttrs<Attrs, State> {
dom: HTMLElement
dom: HTMLElement;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion framework/core/js/src/common/components/LinkButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class LinkButton extends Button {
view(vnode) {
const vdom = super.view(vnode);

vdom.m = (vdom.m & ~m.TYPE_MASK) | (m.TYPE_COMPONENT & m.TYPE_MASK);; // make it component
vdom.m = (vdom.m & ~m.TYPE_MASK) | (m.TYPE_COMPONENT & m.TYPE_MASK); // make it component
vdom.t = m.component(Link);
vdom.a.children = vdom.c;
vdom.a.active = String(vdom.a.active);
Expand Down
22 changes: 8 additions & 14 deletions framework/core/js/src/common/helpers/listItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ export default function listItems<Attrs extends ComponentAttrs>(
item.a.key = item.a.key || item.itemName;
const key = item.a.key;

return m.keyed([key], (key) => [
key,
item
]);
return m.keyed([key], (key) => [key, item]);
}

if (isVnode(item)) {
Expand All @@ -86,15 +83,12 @@ export default function listItems<Attrs extends ComponentAttrs>(
}

const key = (isVnode(item) && item?.a?.key) || item.itemName;
const child = <Tag className={classList(classes)} {...attributes}>
{cloneVnode(item)}
</Tag>;

return key ? m.keyed([key], (key) =>
[
key,
child
]) : child;
const child = (
<Tag className={classList(classes)} {...attributes}>
{cloneVnode(item)}
</Tag>
);

return key ? m.keyed([key], (key) => [key, child]) : child;
});
}

5 changes: 1 addition & 4 deletions framework/core/js/src/common/resolvers/DefaultResolver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ export default class DefaultResolver<
}

render(comp: Comp, attrs: Attrs) {
return m.keyed([this.makeKey()], (key) => [
key,
m(comp, this.makeAttrs(attrs))
]);
return m.keyed([this.makeKey()], (key) => [key, m(comp, this.makeAttrs(attrs))]);
}
}
24 changes: 12 additions & 12 deletions framework/core/js/src/common/utils/cloneVnode.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export default function cloneVnode(vnode: any): any {
if (Array.isArray(vnode)) return vnode.map((v) => cloneVnode(v));
if (typeof vnode !== 'object' || vnode === null || !('m' in vnode)) return vnode;
let children: any[] = [];
if (Array.isArray(vnode.c)) {
for (const i in (vnode.c as any[])) {
children[i] = cloneVnode(vnode.c[i]);
}
if (Array.isArray(vnode)) return vnode.map((v) => cloneVnode(v));
if (typeof vnode !== 'object' || vnode === null || !('m' in vnode)) return vnode;
let children: any[] = [];
if (Array.isArray(vnode.c)) {
for (const i in vnode.c as any[]) {
children[i] = cloneVnode(vnode.c[i]);
}
return {
...vnode,
c: vnode.c ? children : vnode.c
};
}
}
return {
...vnode,
c: vnode.c ? children : vnode.c,
};
}
Loading

0 comments on commit fcf70dd

Please sign in to comment.