oc-template-solid-compiler 0.6.4 → 0.7.1

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 CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "oc-template-solid-compiler",
3
- "version": "0.6.4",
3
+ "version": "0.7.1",
4
4
  "description": "Compiler for the SolidJS OC template",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc && tsc --project tsconfig.solid.json",
9
- "prepare": "npm run build",
10
9
  "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
11
10
  },
12
11
  "repository": {
@@ -30,7 +29,7 @@
30
29
  "license": "MIT",
31
30
  "dependencies": {
32
31
  "oc-template-solid": "^0.1.1",
33
- "oc-vite-compiler": "^3.4.0",
32
+ "oc-vite-compiler": "^3.5.2",
34
33
  "solid-js": "^1.8.7",
35
34
  "vite-plugin-solid": "^2.8.0"
36
35
  },
@@ -33,8 +33,8 @@
33
33
  "@testing-library/jest-dom": "^5.16.5",
34
34
  "@types/testing-library__jest-dom": "^5.14.5",
35
35
  "jsdom": "^21.1.1",
36
- "oc-server": "*",
37
- "oc-template-solid-compiler": "*",
36
+ "oc-server": "^0.3.0",
37
+ "oc-template-solid-compiler": "^0.7.0",
38
38
  "solid-js": "^1.8.7",
39
39
  "typescript": "5.0.2",
40
40
  "vitest": "^0.29.7"
@@ -1,21 +1,18 @@
1
1
  import { createSignal, Show, For } from 'solid-js';
2
- import { useData } from 'oc-template-solid-compiler/dist/utils/useData';
3
- import { serverClient } from 'oc-server';
2
+ import { serverClient, InitialData, ActionOutput } from 'oc-server';
4
3
  import styles from './styles.css';
5
- import type { AdditionalData, ClientProps } from './types';
4
+ import logo from '../public/logo.png';
6
5
 
7
- interface AppProps extends ClientProps {
8
- getMoreData?: boolean;
9
- }
6
+ type AdditionalData = ActionOutput<'funFact'>;
10
7
 
11
- const App = () => {
12
- const { firstName, lastName, userId, getSetting } = useData<AppProps>();
13
- const staticPath = getSetting('staticPath');
14
- const [additionalData, setAdditionalData] = createSignal<AdditionalData | null>(null);
8
+ const App = (props: InitialData) => {
9
+ const { firstName, lastName, born, hobbies } = props;
10
+ const [additionalData, setAdditionalData] =
11
+ createSignal<AdditionalData | null>(null);
15
12
  const [error, setError] = createSignal('');
16
13
 
17
14
  async function handleClick() {
18
- const data = await serverClient.getMoreData({ userId });
15
+ const data = await serverClient.funFact({ year: born });
19
16
 
20
17
  try {
21
18
  setAdditionalData(data);
@@ -27,20 +24,23 @@ const App = () => {
27
24
  return (
28
25
  <Show when={!error()} fallback={<div>Something wrong happened!</div>}>
29
26
  <div class={styles.container}>
30
- <img width="50" height="50" src={`${staticPath}/public/logo.png`} alt="Logo" />
27
+ <img width="50" height="50" src={logo} alt="Logo" />
31
28
  <h1 style={{ margin: '0 0 20px 0' }}>
32
- Hello, <span style={{ 'text-decoration': 'underline' }}>{firstName}</span> {lastName}
29
+ Hello,{' '}
30
+ <span style={{ 'text-decoration': 'underline' }}>{firstName}</span>{' '}
31
+ {lastName}
33
32
  </h1>
34
- <Show when={!!additionalData()}>
35
- <div class={styles.info}>
36
- <div class={styles.block}>Age: {additionalData()!.age}</div>
37
- <div class={styles.block}>
38
- Hobbies: <For each={additionalData()!.hobbies}>{(hobby) => <div>{hobby}</div>}</For>
39
- </div>
33
+ <div class={styles.info}>
34
+ <div class={styles.block}>Born: {born}</div>
35
+ <div class={styles.block}>
36
+ Hobbies: {hobbies.map((x) => x.toLowerCase()).join(', ')}
40
37
  </div>
38
+ </div>
39
+ <Show when={additionalData()}>
40
+ <div>{additionalData()!.funFact}</div>
41
41
  </Show>
42
42
  <button class={styles.button} onClick={handleClick}>
43
- Get extra information
43
+ Fun year fact
44
44
  </button>
45
45
  </div>
46
46
  </Show>
@@ -1,31 +1,45 @@
1
1
  import { Server } from 'oc-server';
2
- import { ClientProps, OcParameters } from './types';
3
2
 
4
- const database = [
5
- { name: 'John Doe', age: 34, hobbies: ['Swimming', 'Basketball'] },
6
- { name: 'Jane Doe', age: 35, hobbies: ['Running', 'Rugby'] }
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 database[userId];
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: OcParameters): Promise<ClientProps> => {
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('getMoreData', async (params: OcParameters) => {
24
- const { userId } = params;
25
- const user = await getUser(userId);
37
+ }).action('funFact', async (params: { year: number }) => {
38
+ const { year } = params;
39
+ const funFact = await getFunFact(year);
40
+
26
41
  return {
27
- age: user.age,
28
- hobbies: user.hobbies
42
+ funFact,
29
43
  };
30
44
  });
31
45