oc-template-vue-compiler 0.2.0 → 0.2.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/package.json +2 -2
- package/scaffold/src/package.json +3 -3
- package/scaffold/src/src/App.vue +24 -13
- package/scaffold/src/src/server.ts +28 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oc-template-vue-compiler",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Compiler for the vueJS OC template",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@vitejs/plugin-vue": "^4.5.2",
|
|
32
32
|
"oc-template-vue": "^0.1.0",
|
|
33
|
-
"oc-vite-compiler": "^3.5.
|
|
33
|
+
"oc-vite-compiler": "^3.5.4"
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
36
36
|
"dist/**",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "base-component-
|
|
2
|
+
"name": "base-component-vue",
|
|
3
3
|
"description": "",
|
|
4
4
|
"version": "1.0.0",
|
|
5
5
|
"scripts": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"@types/testing-library__jest-dom": "^5.14.5",
|
|
34
34
|
"@vitejs/plugin-vue": "^5.0.0",
|
|
35
35
|
"jsdom": "^21.1.1",
|
|
36
|
-
"oc-server": "
|
|
37
|
-
"oc-template-vue-compiler": "
|
|
36
|
+
"oc-server": "^0.3.0",
|
|
37
|
+
"oc-template-vue-compiler": "^0.2.0",
|
|
38
38
|
"typescript": "5.0.2",
|
|
39
39
|
"vitest": "^0.29.7",
|
|
40
40
|
"vue": "^3.3.11",
|
package/scaffold/src/src/App.vue
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
import { ref } from 'vue'
|
|
3
3
|
import logo from '../public/logo.png';
|
|
4
4
|
import { serverClient, ActionOutput } from 'oc-server'
|
|
5
|
-
const props = defineProps<{
|
|
5
|
+
const props = defineProps<{ firstName: string, lastName: string, born: number, hobbies: string[] }>()
|
|
6
6
|
|
|
7
|
-
const additionalData = ref<ActionOutput<'
|
|
8
|
-
async function
|
|
9
|
-
additionalData.value = await serverClient.
|
|
7
|
+
const additionalData = ref<ActionOutput<'funFact'> | null>(null);
|
|
8
|
+
async function getFunFact() {
|
|
9
|
+
additionalData.value = await serverClient.funFact({ year: props.born });
|
|
10
10
|
}
|
|
11
|
+
const hobbies = props.hobbies.map((x) => x.toLowerCase()).join(', ')
|
|
11
12
|
</script>
|
|
12
13
|
|
|
13
14
|
<template>
|
|
@@ -17,17 +18,15 @@ async function getAdditionalData() {
|
|
|
17
18
|
<h1>
|
|
18
19
|
Hello, <span>{{ firstName }}</span> {{ lastName }}
|
|
19
20
|
</h1>
|
|
20
|
-
<div className=
|
|
21
|
-
<div className=
|
|
22
|
-
<div className=
|
|
23
|
-
Hobbies:
|
|
24
|
-
<span v-for="hobby in additionalData.hobbies" :key="hobby">
|
|
25
|
-
{{ hobby.toLowerCase() }}
|
|
26
|
-
</span>
|
|
21
|
+
<div className="info">
|
|
22
|
+
<div className="block">Born: {{ born }}</div>
|
|
23
|
+
<div className="block">
|
|
24
|
+
Hobbies: {{ hobbies }}
|
|
27
25
|
</div>
|
|
28
26
|
</div>
|
|
29
|
-
<
|
|
30
|
-
|
|
27
|
+
<div v-if="additionalData">{{ additionalData?.funFact }}</div>
|
|
28
|
+
<button className="button" @click="getFunFact">
|
|
29
|
+
Fun year fact
|
|
31
30
|
</button>
|
|
32
31
|
</div>
|
|
33
32
|
</template>
|
|
@@ -52,6 +51,10 @@ async function getAdditionalData() {
|
|
|
52
51
|
cursor: pointer;
|
|
53
52
|
}
|
|
54
53
|
|
|
54
|
+
.button:hover {
|
|
55
|
+
background-color: #c79535;
|
|
56
|
+
}
|
|
57
|
+
|
|
55
58
|
h1 {
|
|
56
59
|
margin: 0 0 20px 0;
|
|
57
60
|
}
|
|
@@ -59,4 +62,12 @@ h1 {
|
|
|
59
62
|
span {
|
|
60
63
|
text-decoration: underline;
|
|
61
64
|
}
|
|
65
|
+
|
|
66
|
+
.info {
|
|
67
|
+
margin-bottom: 20px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.block {
|
|
71
|
+
margin: 6px 0;
|
|
72
|
+
}
|
|
62
73
|
</style>
|
|
@@ -1,31 +1,45 @@
|
|
|
1
1
|
import { Server } from 'oc-server';
|
|
2
|
-
import { 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:
|
|
22
|
+
export const server = new Server(async (params: { userId: number }) => {
|
|
14
23
|
const { userId } = params;
|
|
15
24
|
const user = await getUser(userId);
|
|
16
|
-
|
|
17
25
|
const [firstName, lastName] = user.name.split(/\s+/);
|
|
26
|
+
|
|
27
|
+
if (firstName === 'Invalid') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
return {
|
|
19
|
-
userId,
|
|
20
32
|
firstName,
|
|
21
|
-
lastName
|
|
33
|
+
lastName,
|
|
34
|
+
born: user.born,
|
|
35
|
+
hobbies: user.hobbies,
|
|
22
36
|
};
|
|
23
|
-
}).action('
|
|
24
|
-
const {
|
|
25
|
-
const
|
|
37
|
+
}).action('funFact', async (params: { year: number }) => {
|
|
38
|
+
const { year } = params;
|
|
39
|
+
const funFact = await getFunFact(year);
|
|
40
|
+
|
|
26
41
|
return {
|
|
27
|
-
|
|
28
|
-
hobbies: user.hobbies
|
|
42
|
+
funFact,
|
|
29
43
|
};
|
|
30
44
|
});
|
|
31
45
|
|