oc-template-preact-compiler 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils/useData.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ type PromiseData<T = any> = T & {
|
|
|
2
2
|
getData<O = any>(parameters?: Partial<T>): Promise<O>;
|
|
3
3
|
getSetting(setting: 'name' | 'version' | 'baseUrl' | 'staticPath'): string;
|
|
4
4
|
};
|
|
5
|
-
export declare const DataProvider: ({ children, ...props }: any) => import("
|
|
5
|
+
export declare const DataProvider: ({ children, ...props }: any) => import("preact").JSX.Element;
|
|
6
6
|
export declare function useData<T = any>(): PromiseData<T>;
|
|
7
7
|
export {};
|
package/dist/utils/useData.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useData = exports.DataProvider = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("
|
|
4
|
+
const jsx_runtime_1 = require("preact/jsx-runtime");
|
|
5
5
|
const preact_1 = require("preact");
|
|
6
6
|
const hooks_1 = require("preact/hooks");
|
|
7
7
|
const DataContext = (0, preact_1.createContext)({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oc-template-preact-compiler",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Compiler for the Preact OC template",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
},
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@preact/preset-vite": "^2.
|
|
31
|
+
"@preact/preset-vite": "^2.7.0",
|
|
32
32
|
"oc-template-preact": "^0.1.1",
|
|
33
|
-
"oc-vite-compiler": "^3.5.
|
|
33
|
+
"oc-vite-compiler": "^3.5.2",
|
|
34
34
|
"preact": "^10"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "base-component-
|
|
2
|
+
"name": "base-component-preact",
|
|
3
3
|
"description": "",
|
|
4
4
|
"version": "1.0.0",
|
|
5
5
|
"scripts": {
|
|
@@ -30,11 +30,12 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {},
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"@preact/preset-vite": "^2.7.0",
|
|
33
34
|
"@testing-library/react": "^14.0.0",
|
|
34
35
|
"@testing-library/user-event": "^14.4.3",
|
|
35
36
|
"jsdom": "^21.1.1",
|
|
36
|
-
"oc-server": "
|
|
37
|
-
"oc-template-preact-compiler": "0.
|
|
37
|
+
"oc-server": "^0.3.0",
|
|
38
|
+
"oc-template-preact-compiler": "^0.4.1",
|
|
38
39
|
"preact": "^10.13.2",
|
|
39
40
|
"typescript": "5.0.2",
|
|
40
41
|
"vitest": "^0.29.7"
|
package/scaffold/src/src/App.tsx
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
import { useState } from 'preact/hooks';
|
|
2
|
-
import {
|
|
3
|
-
import { serverClient } from 'oc-server';
|
|
2
|
+
import { ActionOutput, InitialData, serverClient } from 'oc-server';
|
|
4
3
|
import styles from './styles.css';
|
|
5
|
-
import
|
|
4
|
+
import logo from '../public/logo.png';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
getMoreData?: boolean;
|
|
9
|
-
}
|
|
6
|
+
type AdditionalData = ActionOutput<'funFact'>;
|
|
10
7
|
|
|
11
|
-
const App = () => {
|
|
12
|
-
const { firstName, lastName,
|
|
13
|
-
const
|
|
14
|
-
|
|
8
|
+
const App = (props: InitialData) => {
|
|
9
|
+
const { firstName, lastName, born, hobbies } = props;
|
|
10
|
+
const [additionalData, setAdditionalData] = useState<AdditionalData | null>(
|
|
11
|
+
null
|
|
12
|
+
);
|
|
15
13
|
const [error, setError] = useState('');
|
|
16
14
|
|
|
17
|
-
const
|
|
15
|
+
const getFunFact = async () => {
|
|
18
16
|
setError('');
|
|
19
17
|
try {
|
|
20
|
-
const data = await serverClient.
|
|
18
|
+
const data = await serverClient.funFact({ year: born });
|
|
21
19
|
setAdditionalData(data);
|
|
22
20
|
} catch (err) {
|
|
23
21
|
setError(String(err));
|
|
@@ -30,20 +28,20 @@ const App = () => {
|
|
|
30
28
|
|
|
31
29
|
return (
|
|
32
30
|
<div className={styles.container}>
|
|
33
|
-
<img width="50" height="50" src={
|
|
31
|
+
<img width="50" height="50" src={logo} alt="Logo" />
|
|
34
32
|
<h1 style={{ margin: '0 0 20px 0' }}>
|
|
35
|
-
Hello, <span style={{ textDecoration: 'underline' }}>{firstName}</span>
|
|
33
|
+
Hello, <span style={{ textDecoration: 'underline' }}>{firstName}</span>{' '}
|
|
34
|
+
{lastName}
|
|
36
35
|
</h1>
|
|
37
|
-
{
|
|
38
|
-
<div className={styles.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Hobbies: {additionalData.hobbies.map((x) => x.toLowerCase()).join(', ')}
|
|
42
|
-
</div>
|
|
36
|
+
<div className={styles.info}>
|
|
37
|
+
<div className={styles.block}>Born: {born}</div>
|
|
38
|
+
<div className={styles.block}>
|
|
39
|
+
Hobbies: {hobbies.map((x) => x.toLowerCase()).join(', ')}
|
|
43
40
|
</div>
|
|
44
|
-
|
|
45
|
-
<
|
|
46
|
-
|
|
41
|
+
</div>
|
|
42
|
+
{additionalData && <div>{additionalData.funFact}</div>}
|
|
43
|
+
<button className={styles.button} onClick={getFunFact}>
|
|
44
|
+
Fun year fact
|
|
47
45
|
</button>
|
|
48
46
|
</div>
|
|
49
47
|
);
|
|
@@ -1,30 +1,45 @@
|
|
|
1
1
|
import { Server } from 'oc-server';
|
|
2
|
-
import { AdditionalData, ClientProps, OcParameters } from './types';
|
|
3
2
|
|
|
4
|
-
const
|
|
5
|
-
{ name: 'John Doe',
|
|
6
|
-
{ name: 'Jane Doe',
|
|
3
|
+
const userDatabase = [
|
|
4
|
+
{ name: 'John Doe', born: 1986, hobbies: ['Swimming', 'Basketball'] },
|
|
5
|
+
{ name: 'Jane Doe', born: 1991, hobbies: ['Running', 'Rugby'] },
|
|
7
6
|
];
|
|
8
7
|
|
|
8
|
+
const yearsFunFactDatabase: Record<number, string> = {
|
|
9
|
+
1986: "Halley's Comet made its closest approach to Earth in 1986, visible to the naked eye.",
|
|
10
|
+
1987: 'The first Final Fantasy game was released in 1987.',
|
|
11
|
+
1991: 'The first web page was created in 1991 by Tim Berners-Lee.',
|
|
12
|
+
};
|
|
13
|
+
|
|
9
14
|
async function getUser(userId: number) {
|
|
10
|
-
return
|
|
15
|
+
return userDatabase[userId];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function getFunFact(year: number) {
|
|
19
|
+
return yearsFunFactDatabase[year];
|
|
11
20
|
}
|
|
12
21
|
|
|
13
|
-
export const server = new Server(async (params:
|
|
14
|
-
const
|
|
22
|
+
export const server = new Server(async (params: { userId: number }) => {
|
|
23
|
+
const { userId } = params;
|
|
24
|
+
const user = await getUser(userId);
|
|
15
25
|
const [firstName, lastName] = user.name.split(/\s+/);
|
|
16
26
|
|
|
27
|
+
if (firstName === 'Invalid') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
17
31
|
return {
|
|
18
|
-
userId: params.userId,
|
|
19
32
|
firstName,
|
|
20
|
-
lastName
|
|
33
|
+
lastName,
|
|
34
|
+
born: user.born,
|
|
35
|
+
hobbies: user.hobbies,
|
|
21
36
|
};
|
|
22
|
-
}).action('
|
|
23
|
-
const
|
|
37
|
+
}).action('funFact', async (params: { year: number }) => {
|
|
38
|
+
const { year } = params;
|
|
39
|
+
const funFact = await getFunFact(year);
|
|
24
40
|
|
|
25
41
|
return {
|
|
26
|
-
|
|
27
|
-
hobbies: user.hobbies
|
|
42
|
+
funFact,
|
|
28
43
|
};
|
|
29
44
|
});
|
|
30
45
|
|
|
@@ -20,7 +20,11 @@
|
|
|
20
20
|
"resolveJsonModule": true,
|
|
21
21
|
"isolatedModules": true,
|
|
22
22
|
"jsx": "react-jsx",
|
|
23
|
-
"jsxImportSource": "preact"
|
|
23
|
+
"jsxImportSource": "preact",
|
|
24
|
+
"paths": {
|
|
25
|
+
"react": ["./node_modules/preact/compat/"],
|
|
26
|
+
"react-dom": ["./node_modules/preact/compat/"]
|
|
27
|
+
}
|
|
24
28
|
},
|
|
25
29
|
"include": ["src"],
|
|
26
30
|
"exclude": ["src/_package"]
|