oc-template-preact-compiler 0.3.0-beta.1 → 0.3.0-beta.3
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/lib/htmlTemplate.js
CHANGED
|
@@ -7,8 +7,8 @@ const cssesc_1 = __importDefault(require("cssesc"));
|
|
|
7
7
|
function viewTemplate({ templateId, css, bundle, hash }) {
|
|
8
8
|
return `function(model){
|
|
9
9
|
var modelHTML = model.__html ? model.__html : '';
|
|
10
|
-
var staticPath = model.
|
|
11
|
-
var props = JSON.stringify(model.
|
|
10
|
+
var staticPath = model.component.props._staticPath;
|
|
11
|
+
var props = JSON.stringify(model.component.props);
|
|
12
12
|
window.oc = window.oc || {};
|
|
13
13
|
window.oc.__typescriptReactTemplate = window.oc.__typescriptReactTemplate || { count: 0 };
|
|
14
14
|
oc.preactComponents = oc.preactComponents || {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oc-template-preact-compiler",
|
|
3
|
-
"version": "0.3.0-beta.
|
|
3
|
+
"version": "0.3.0-beta.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"immer": "^9.0.6",
|
|
36
36
|
"oc-generic-template-compiler": "2.1.0",
|
|
37
37
|
"oc-statics-compiler": "2.1.1",
|
|
38
|
-
"oc-template-preact": "
|
|
38
|
+
"oc-template-preact": "0.1.0-beta.0",
|
|
39
39
|
"oc-vite-compiler": "3.0.0-beta.2",
|
|
40
40
|
"preact": "^10",
|
|
41
41
|
"resolve": "^1.20.0"
|
package/scaffold/src/src/App.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState } from 'preact/hooks';
|
|
2
2
|
import { useData } from 'oc-template-preact-compiler/dist/utils/useData';
|
|
3
|
+
import { serverClient } from 'oc-server';
|
|
3
4
|
import styles from './styles.css';
|
|
4
5
|
import type { AdditionalData, ClientProps } from './types';
|
|
5
6
|
|
|
@@ -16,7 +17,7 @@ const App = () => {
|
|
|
16
17
|
const fetchMoreData = async () => {
|
|
17
18
|
setError('');
|
|
18
19
|
try {
|
|
19
|
-
const data = await
|
|
20
|
+
const data = await serverClient.getMoreData({ userId });
|
|
20
21
|
setAdditionalData(data);
|
|
21
22
|
} catch (err) {
|
|
22
23
|
setError(String(err));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Server } from 'oc-server';
|
|
2
2
|
import { AdditionalData, ClientProps, OcParameters } from './types';
|
|
3
3
|
|
|
4
4
|
const database = [
|
|
@@ -10,25 +10,26 @@ async function getUser(userId: number) {
|
|
|
10
10
|
return database[userId];
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export async
|
|
14
|
-
|
|
15
|
-
callback: (error: any, data: ClientProps | AdditionalData) => void
|
|
16
|
-
) {
|
|
17
|
-
const { userId } = context.params;
|
|
18
|
-
const user = await getUser(userId);
|
|
19
|
-
const shouldGetMoreData = context.params.getMoreData;
|
|
13
|
+
export const server = new Server(async (params: OcParameters): Promise<ClientProps> => {
|
|
14
|
+
const user = await getUser(params.userId);
|
|
20
15
|
const [firstName, lastName] = user.name.split(/\s+/);
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
age: user.age,
|
|
25
|
-
hobbies: user.hobbies
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return callback(null, {
|
|
30
|
-
userId,
|
|
17
|
+
return {
|
|
18
|
+
userId: params.userId,
|
|
31
19
|
firstName,
|
|
32
20
|
lastName
|
|
33
|
-
}
|
|
21
|
+
};
|
|
22
|
+
}).action('getMoreData', async (params: OcParameters): Promise<AdditionalData> => {
|
|
23
|
+
const user = await getUser(params.userId);
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
age: user.age,
|
|
27
|
+
hobbies: user.hobbies
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
declare module 'oc-server' {
|
|
32
|
+
interface Register {
|
|
33
|
+
server: typeof server;
|
|
34
|
+
}
|
|
34
35
|
}
|