Skip to content

Commit

Permalink
Rename pathOf to path (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikb authored Jul 24, 2021
1 parent e95de9a commit 40e86e7
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 81 deletions.
6 changes: 3 additions & 3 deletions examples/data-attributes/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ interface Data {
toggle: boolean;
}

const { React, init, don, pathOf, data } = domdom<Data>({
const { React, init, don, path, data } = domdom<Data>({
toggle: false,
});

const view = (
<div>
<button onClick={() => (data.toggle = !data.toggle)}>Toggle</button>
<button disabled={don(pathOf().toggle)}>A</button>
<button disabled={don(pathOf().toggle).map(res => !res)}>B</button>
<button disabled={don(path().toggle)}>A</button>
<button disabled={don(path().toggle).map(res => !res)}>B</button>
</div>
);
// Important part
Expand Down
4 changes: 2 additions & 2 deletions examples/data-set/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ interface Data {
hello: string;
}

const { React, init, don, pathOf, data } = domdom<Data>({
const { React, init, don, path, data } = domdom<Data>({
hello: 'World!',
});

const view = (
<div>
<div>A: Hello, {data.hello}</div>
<div>B: Hello, {don(pathOf().hello)}</div>
<div>B: Hello, {don(path().hello)}</div>
<div>
<button onClick={() => (data.hello = 'there!')}>Click me!</button>
</div>
Expand Down
4 changes: 2 additions & 2 deletions examples/dd-model/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ interface Data {
hello: string;
}

const { React, init, don, pathOf } = domdom<Data>({
const { React, init, don, path } = domdom<Data>({
hello: 'World!',
});

const view = (
<div>
<div>Hello, {don(pathOf().hello)}</div>
<div>Hello, {don(path().hello)}</div>
<div>
<input type="text" dd-model="hello" />
</div>
Expand Down
6 changes: 3 additions & 3 deletions examples/don-children/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ interface Data {
users: User[];
}

const { React, init, don, data, pathOf } = domdom<Data>({
const { React, init, don, data, path } = domdom<Data>({
users: [{ name: 'Hello' }, { name: 'World' }, { name: 'Yup' }],
});

const view = (
<div>
<ul>
{don(pathOf().users.$).map(user => (
<li>{don(pathOf(user).name)}</li>
{don(path().users.$).map(user => (
<li>{don(path(user).name)}</li>
))}
</ul>
<button onClick={() => (data.users[1].name = '🤷')}>Click me!</button>
Expand Down
4 changes: 2 additions & 2 deletions examples/don-wildcard/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ interface Data {
users: User[];
}

const { React, init, don, pathOf } = domdom<Data>({
const { React, init, don, path } = domdom<Data>({
users: [{ name: 'Hello' }, { name: 'World' }],
});

const view = (
<ul>
{don(pathOf().users.$).map(user => (
{don(path().users.$).map(user => (
<li>{user.name}</li>
))}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions examples/don/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ interface Data {
hello: string;
}

const { React, init, don, pathOf } = domdom<Data>({
const { React, init, don, path } = domdom<Data>({
hello: 'World!',
});

const view = <span>{don(pathOf().hello)}</span>;
const view = <span>{don(path().hello)}</span>;
// Important part

init(document.body, view);
4 changes: 2 additions & 2 deletions examples/pathifier-on/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface Data {
desc: boolean;
}

const { React, init, don, pathOf, data } = domdom<Data>({
const { React, init, don, path, data } = domdom<Data>({
users: [{ name: 'Yup' }, { name: 'World' }, { name: 'Hello' }],
filter: '',
desc: false,
Expand All @@ -25,7 +25,7 @@ const view = (
<input type="text" placeholder="filter" dd-model="filter" />

<ul>
{don(pathOf().users)
{don(path().users)
.filterOn('filter', (user, { onValue }) => user.name.includes(onValue))
.sortOn('desc', (a, b, { onValue }) =>
onValue ? b.name.localeCompare(a.name) : a.name.localeCompare(b.name)
Expand Down
4 changes: 2 additions & 2 deletions examples/pathifier/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ interface Data {
users: User[];
}

const { React, init, don, pathOf } = domdom<Data>({
const { React, init, don, path } = domdom<Data>({
users: [{ name: 'Yup' }, { name: 'World' }, { name: 'Hello' }],
});

const view = (
<ul>
{don(pathOf().users.$)
{don(path().users.$)
.filter(user => user.name !== 'World')
.sort((a, b) => a.name.localeCompare(b.name))
.map(user => (
Expand Down
4 changes: 2 additions & 2 deletions examples/routing/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface Data {
route: Route;
}

const { React, init, don, pathOf, data } = domdom<Data>({ route: 'panel-a' });
const { React, init, don, path, data } = domdom<Data>({ route: 'panel-a' });

const PanelA = () => (
<div>
Expand All @@ -18,7 +18,7 @@ const PanelB = () => <div>Panel B! (hash is: {window.location.hash})</div>;

const view = (
<div>
{don(pathOf().route).map((route: Route) => {
{don(path().route).map((route: Route) => {
switch (route) {
case 'panel-b':
return <PanelB />;
Expand Down
4 changes: 2 additions & 2 deletions examples/structure/app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { data, don, init, pathOf, React } from './domdom';
import { data, don, init, path, React } from './domdom';

const view = <div>Hello, {don(pathOf().hello)}</div>;
const view = <div>Hello, {don(path().hello)}</div>;

data.hello = 'There :)';

Expand Down
2 changes: 1 addition & 1 deletion examples/structure/domdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export const React = dd.React;
export const init = dd.init;
export const data = dd.data;
export const don = dd.don;
export const pathOf = dd.pathOf;
export const path = dd.path;
4 changes: 2 additions & 2 deletions examples/ticks/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface Data {
tick: number;
}

const { React, init, don, pathOf, data } = domdom<Data>({
const { React, init, don, path, data } = domdom<Data>({
run: false,
tick: 0,
});
Expand All @@ -14,7 +14,7 @@ const view = (
<div>
<img
src="https://i.imgur.com/rsD0RUq.jpg"
style={don(pathOf().tick).map(tick => ({ rotate: `${tick % 180}deg` }))}
style={don(path().tick).map(tick => ({ rotate: `${tick % 180}deg` }))}
/>
<button onClick={() => (data.run = !data.run)}>Start/Stop</button>
</div>
Expand Down
40 changes: 20 additions & 20 deletions src/godmode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const p = (o, path: string[] = [], hack = false) => {
});
};

function pathus(path: string | PathOf): string {
function pathus(path: string | Path): string {
if (typeof path === 'string') return path;
return path.$path;
}
Expand Down Expand Up @@ -115,7 +115,7 @@ export class GodMode<T> {
});
}

don = (path: string | PathOf): Pathifier => {
don = (path: string | Path): Pathifier => {
const pathAsString = pathus(path);

const self = this;
Expand Down Expand Up @@ -148,26 +148,26 @@ export class GodMode<T> {
return pathifier;
};

trigger = (path: string | PathOf, value?: any) => {
trigger = (path: string | Path, value?: any) => {
return this.domdom.trigger(pathus(path), value);
};

get = <T = any>(path?: string | PathOf): T | undefined => {
get = <T = any>(path?: string | Path): T | undefined => {
if (!path) return this.domdom.get();
return this.domdom.get(pathus(path));
};

set = (path: string | PathOf, value: any, byKey?: string) => {
set = (path: string | Path, value: any, byKey?: string) => {
this.domdom.set(pathus(path), value, byKey);
};

unset = (path: string | PathOf) => {
unset = (path: string | Path) => {
this.domdom.unset(pathus(path));
};

on = <T = any>(
flags: string,
path: string | PathOf,
path: string | Path,
listener: ListenerCallbackWithType<T>
): string => {
return this.domdom.on([flags, pathus(path)].join(' '), (value, opts) =>
Expand All @@ -178,31 +178,31 @@ export class GodMode<T> {
init = (parent: HTMLElement, child?: HTMLElement) =>
this.domdom.init(parent, child);

pathOf<X = T>(o?: X): PathOf<X> {
return p(o) as PathOf<X>;
path<X = T>(o?: X): Path<X> {
return p(o) as Path<X>;
}
}

export type PathOf<T = unknown> = {
[P in keyof T]: PathOf<T[P]>;
export type Path<T = unknown> = {
[P in keyof T]: Path<T[P]>;
} &
(T extends Array<infer A>
? {
$path: string;
$: PathOf<A>;
$x: PathOf<A>;
$xx: PathOf<A>;
$: Path<A>;
$x: Path<A>;
$xx: Path<A>;
$$: {
[key: string]: PathOf<A>;
[key: string]: Path<A>;
};
[index: number]: PathOf<A>;
[index: number]: Path<A>;
}
: {
$path: string;
$: PathOf<T>;
$x: PathOf<T>;
$xx: PathOf<T>;
$: Path<T>;
$x: Path<T>;
$xx: Path<T>;
$$: {
[key: string]: PathOf<T>;
[key: string]: Path<T>;
};
});
Loading

0 comments on commit 40e86e7

Please sign in to comment.