frontend-hamroun 1.2.80 → 1.2.83
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/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.client.cjs +1 -1
- package/dist/index.client.js +2 -2
- package/dist/index.js +11 -7
- package/dist/index.js.map +1 -1
- package/dist/{renderer-Din1y3YM.cjs → renderer-BL3gq8cW.cjs} +2 -2
- package/dist/{renderer-Din1y3YM.cjs.map → renderer-BL3gq8cW.cjs.map} +1 -1
- package/dist/{renderer-Bo9zkUZ_.js → renderer-Dyy-o05F.js} +2 -2
- package/dist/{renderer-Bo9zkUZ_.js.map → renderer-Dyy-o05F.js.map} +1 -1
- package/dist/{server-renderer-QHt45Ip2.js → server-renderer-C1WXH-zV.js} +99 -73
- package/dist/server-renderer-C1WXH-zV.js.map +1 -0
- package/dist/server-renderer-Chs-nmJm.cjs +2 -0
- package/dist/server-renderer-Chs-nmJm.cjs.map +1 -0
- package/dist/server-renderer.cjs +1 -1
- package/dist/server-renderer.js +1 -1
- package/package.json +1 -1
- package/templates/basic-app/src/App.jsx +16 -0
- package/templates/basic-app/src/client.jsx +5 -0
- package/templates/basic-app/src/components/Counter.jsx +13 -0
- package/templates/basic-app/src/jsx-shim.js +3 -0
- package/templates/basic-app/src/jsx-shim.ts +7 -0
- package/templates/basic-app/src/main.jsx +98 -0
- package/templates/basic-app/src/server.js +47 -0
- package/templates/complete-app/api/hello.js +0 -0
- package/templates/complete-app/lib/frontend-hamroun.js +182 -0
- package/templates/complete-app/package.json +18 -0
- package/templates/complete-app/pages/about.js +119 -0
- package/templates/complete-app/pages/about.jsx +0 -0
- package/templates/complete-app/pages/index.js +157 -0
- package/templates/complete-app/pages/index.jsx +0 -0
- package/templates/complete-app/pages/wasm-demo.js +290 -0
- package/templates/complete-app/pages/wasm-demo.jsx +0 -0
- package/templates/complete-app/public/client.js +89 -0
- package/templates/complete-app/public/index.html +118 -0
- package/templates/complete-app/public/styles.css +76 -0
- package/templates/complete-app/server.js +226 -0
- package/templates/complete-app/src/App.tsx +59 -0
- package/templates/complete-app/src/client.tsx +18 -0
- package/templates/complete-app/src/server.ts +218 -0
- package/templates/complete-app/tsconfig.json +22 -0
- package/templates/complete-app/tsconfig.server.json +19 -0
- package/templates/{ssr-template → complete-app}/vite.config.js +16 -5
- package/templates/complete-app/vite.config.ts +30 -0
- package/templates/complete-app/wasm/build.bat +0 -0
- package/templates/complete-app/wasm/build.sh +0 -0
- package/templates/complete-app/wasm/example.go +0 -0
- package/templates/fullstack-app/build/main.css +874 -874
- package/templates/fullstack-app/build/main.css.map +7 -7
- package/templates/fullstack-app/build/main.js +996 -967
- package/templates/fullstack-app/build/main.js.map +7 -7
- package/templates/fullstack-app/package-lock.json +6301 -0
- package/templates/fullstack-app/public/styles.css +768 -768
- package/templates/go/example.go +154 -99
- package/templates/ssr-template/dist/client/assets/main-D-VH3xOb.js +1 -0
- package/templates/ssr-template/dist/client/index.html +23 -0
- package/templates/ssr-template/dist/client.js +951 -0
- package/templates/ssr-template/dist/server.js +739 -0
- package/templates/ssr-template/esbuild.config.js +33 -0
- package/templates/ssr-template/jsx-shim.js +1 -0
- package/templates/ssr-template/package.json +14 -8
- package/templates/ssr-template/src/App.tsx +847 -49
- package/templates/ssr-template/src/client.tsx +3 -17
- package/templates/ssr-template/src/server.ts +21 -204
- package/templates/ssr-template/tsconfig.json +9 -8
- package/templates/ssr-template/tsconfig.server.json +6 -14
- package/templates/ssr-template/vite.config.ts +19 -17
- package/templates/wasm/build-wasm.js +228 -0
- package/templates/wasm/dist/assets/index-BNqTDBdE.js +295 -0
- package/templates/wasm/dist/example.wasm +0 -0
- package/templates/wasm/dist/index.html +53 -0
- package/templates/{go-wasm-app/public/wasm → wasm/dist}/wasm_exec.js +572 -561
- package/templates/wasm/esbuild.config.js +63 -0
- package/templates/wasm/go/main.go +256 -0
- package/templates/wasm/go/wasm_exec.js +0 -0
- package/templates/wasm/index.html +97 -0
- package/templates/wasm/jsx-shim.js +9 -0
- package/templates/wasm/package-lock.json +4577 -0
- package/templates/wasm/package.json +25 -0
- package/templates/wasm/public/example.wasm +0 -0
- package/templates/wasm/public/wasm_exec.js +572 -0
- package/templates/wasm/src/App.tsx +550 -0
- package/templates/wasm/src/client.tsx +220 -0
- package/templates/wasm/src/index.tsx +21 -0
- package/templates/wasm/src/server.ts +145 -0
- package/templates/wasm/tsconfig.json +21 -0
- package/templates/wasm/tsconfig.node.json +13 -0
- package/templates/wasm/tsconfig.server.json +23 -0
- package/templates/wasm/vite.config.ts +38 -0
- package/templates/wasm/wasm-loader.js +103 -0
- package/dist/server-renderer-CqIpQ-od.cjs +0 -2
- package/dist/server-renderer-CqIpQ-od.cjs.map +0 -1
- package/dist/server-renderer-QHt45Ip2.js.map +0 -1
- package/templates/basic-app/bun.lock +0 -196
- package/templates/basic-app/docs/rapport_pfe.aux +0 -27
- package/templates/basic-app/docs/rapport_pfe.out +0 -10
- package/templates/basic-app/docs/rapport_pfe.pdf +0 -0
- package/templates/basic-app/docs/rapport_pfe.tex +0 -68
- package/templates/basic-app/docs/rapport_pfe.toc +0 -14
- package/templates/basic-app/package-lock.json +0 -4185
- package/templates/go-wasm-app/README.md +0 -38
- package/templates/go-wasm-app/babel.config.js +0 -15
- package/templates/go-wasm-app/build-client.js +0 -49
- package/templates/go-wasm-app/build-wasm.js +0 -237
- package/templates/go-wasm-app/package.json +0 -23
- package/templates/go-wasm-app/public/index.html +0 -128
- package/templates/go-wasm-app/public/styles.css +0 -197
- package/templates/go-wasm-app/public/wasm/example.wasm +0 -0
- package/templates/go-wasm-app/public/wasm/wasm_exec_node.js +0 -39
- package/templates/go-wasm-app/server.js +0 -521
- package/templates/go-wasm-app/src/App.jsx +0 -38
- package/templates/go-wasm-app/src/app.js +0 -153
- package/templates/go-wasm-app/src/client.js +0 -57
- package/templates/go-wasm-app/src/components/Footer.jsx +0 -13
- package/templates/go-wasm-app/src/components/Header.jsx +0 -19
- package/templates/go-wasm-app/src/components/WasmDemo.jsx +0 -120
- package/templates/go-wasm-app/src/main.jsx +0 -12
- package/templates/go-wasm-app/src/wasm/example.go +0 -75
- package/templates/go-wasm-app/tsconfig.server.json +0 -18
- package/templates/go-wasm-app/vite.config.js +0 -34
- package/templates/ssr-template/package-lock.json +0 -2478
- package/templates/ssr-template/public/index.html +0 -47
- package/templates/ssr-template/server.js +0 -369
- /package/templates/{ssr-template → complete-app}/client.js +0 -0
- /package/templates/{ssr-template → complete-app}/readme.md +0 -0
- /package/templates/{ssr-template → complete-app}/server.ts +0 -0
- /package/templates/{ssr-template → complete-app}/src/client.ts +0 -0
- /package/templates/{ssr-template → complete-app}/src/pages/index.tsx +0 -0
@@ -1,153 +0,0 @@
|
|
1
|
-
import { useState, useEffect, jsx, Fragment } from 'frontend-hamroun';
|
2
|
-
import { loadGoWasm, createTypedWasmFunction, goValues } from 'frontend-hamroun';
|
3
|
-
|
4
|
-
export function GoWasmDemo() {
|
5
|
-
// Track loading state
|
6
|
-
const [loading, setLoading] = useState(true);
|
7
|
-
const [error, setError] = useState(null);
|
8
|
-
const [wasm, setWasm] = useState(null);
|
9
|
-
|
10
|
-
// Track calculation values
|
11
|
-
const [num1, setNum1] = useState(5);
|
12
|
-
const [num2, setNum2] = useState(7);
|
13
|
-
const [result, setResult] = useState(null);
|
14
|
-
|
15
|
-
// Track JSON example
|
16
|
-
const [jsonInput, setJsonInput] = useState('{"name": "Frontend Hamroun", "version": "1.0"}');
|
17
|
-
const [jsonResult, setJsonResult] = useState(null);
|
18
|
-
|
19
|
-
// Load the WASM module when component mounts
|
20
|
-
useEffect(() => {
|
21
|
-
async function loadWasmModule() {
|
22
|
-
try {
|
23
|
-
setLoading(true);
|
24
|
-
console.log('Loading WASM module...');
|
25
|
-
|
26
|
-
// Load WASM module using frontend-hamroun's loadGoWasm
|
27
|
-
const wasmInstance = await loadGoWasm('/wasm/example.wasm', {
|
28
|
-
debug: true, // Enable debug logging
|
29
|
-
goWasmPath: '/wasm/wasm_exec.js' // Path to Go's wasm_exec.js
|
30
|
-
});
|
31
|
-
|
32
|
-
console.log('WASM module loaded successfully!', wasmInstance);
|
33
|
-
setWasm(wasmInstance);
|
34
|
-
|
35
|
-
// Demonstrate calling a function right away
|
36
|
-
if (wasmInstance.functions.goAdd) {
|
37
|
-
const sum = wasmInstance.functions.goAdd(5, 7);
|
38
|
-
console.log('5 + 7 =', sum);
|
39
|
-
setResult(sum);
|
40
|
-
}
|
41
|
-
|
42
|
-
setLoading(false);
|
43
|
-
} catch (err) {
|
44
|
-
console.error('Failed to load WASM module:', err);
|
45
|
-
setError(err.toString());
|
46
|
-
setLoading(false);
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
loadWasmModule();
|
51
|
-
|
52
|
-
// Cleanup function
|
53
|
-
return () => {
|
54
|
-
console.log('Cleaning up WASM resources...');
|
55
|
-
// Any cleanup needed for WASM resources
|
56
|
-
};
|
57
|
-
}, []); // Empty dependency array means this runs once on mount
|
58
|
-
|
59
|
-
// Function to calculate using WASM
|
60
|
-
const calculateResult = () => {
|
61
|
-
if (!wasm || !wasm.functions.goAdd) {
|
62
|
-
setError('WASM module not loaded or function not available');
|
63
|
-
return;
|
64
|
-
}
|
65
|
-
|
66
|
-
try {
|
67
|
-
// Call the WASM function
|
68
|
-
const sum = wasm.functions.goAdd(parseInt(num1), parseInt(num2));
|
69
|
-
setResult(sum);
|
70
|
-
setError(null);
|
71
|
-
} catch (err) {
|
72
|
-
console.error('Error calling WASM function:', err);
|
73
|
-
setError('Error calling WASM function: ' + err);
|
74
|
-
}
|
75
|
-
};
|
76
|
-
|
77
|
-
// Function to parse JSON using WASM
|
78
|
-
const parseJsonWithWasm = () => {
|
79
|
-
if (!wasm || !wasm.functions.goParseJSON) {
|
80
|
-
setError('WASM module not loaded or JSON parsing function not available');
|
81
|
-
return;
|
82
|
-
}
|
83
|
-
|
84
|
-
try {
|
85
|
-
// Call the WASM function
|
86
|
-
const parsed = wasm.functions.goParseJSON(jsonInput);
|
87
|
-
setJsonResult(JSON.stringify(parsed, null, 2));
|
88
|
-
setError(null);
|
89
|
-
} catch (err) {
|
90
|
-
console.error('Error parsing JSON with WASM:', err);
|
91
|
-
setError('Error parsing JSON with WASM: ' + err);
|
92
|
-
}
|
93
|
-
};
|
94
|
-
|
95
|
-
// Render the component
|
96
|
-
return (
|
97
|
-
<div className="wasm-demo">
|
98
|
-
<h1>Go WebAssembly Demo</h1>
|
99
|
-
|
100
|
-
{loading && <p>Loading WASM module...</p>}
|
101
|
-
|
102
|
-
{error && (
|
103
|
-
<div className="error">
|
104
|
-
<h3>Error:</h3>
|
105
|
-
<pre>{error}</pre>
|
106
|
-
</div>
|
107
|
-
)}
|
108
|
-
|
109
|
-
{wasm && !loading && (
|
110
|
-
<div className="demo-section">
|
111
|
-
<h2>WASM Addition</h2>
|
112
|
-
<div className="calculator">
|
113
|
-
<input
|
114
|
-
type="number"
|
115
|
-
value={num1}
|
116
|
-
onChange={(e) => setNum1(e.target.value)}
|
117
|
-
/>
|
118
|
-
<span> + </span>
|
119
|
-
<input
|
120
|
-
type="number"
|
121
|
-
value={num2}
|
122
|
-
onChange={(e) => setNum2(e.target.value)}
|
123
|
-
/>
|
124
|
-
<button onClick={calculateResult}>Calculate</button>
|
125
|
-
<span className="result">Result: {result}</span>
|
126
|
-
</div>
|
127
|
-
|
128
|
-
<h2>WASM JSON Parsing</h2>
|
129
|
-
<div className="json-parser">
|
130
|
-
<textarea
|
131
|
-
rows="5"
|
132
|
-
value={jsonInput}
|
133
|
-
onChange={(e) => setJsonInput(e.target.value)}
|
134
|
-
/>
|
135
|
-
<button onClick={parseJsonWithWasm}>Parse JSON</button>
|
136
|
-
{jsonResult && (
|
137
|
-
<pre className="json-result">{jsonResult}</pre>
|
138
|
-
)}
|
139
|
-
</div>
|
140
|
-
|
141
|
-
<h2>Available WASM Functions</h2>
|
142
|
-
<ul>
|
143
|
-
{wasm && Object.keys(wasm.functions).map(funcName => (
|
144
|
-
<li key={funcName}>{funcName}</li>
|
145
|
-
))}
|
146
|
-
</ul>
|
147
|
-
</div>
|
148
|
-
)}
|
149
|
-
</div>
|
150
|
-
);
|
151
|
-
}
|
152
|
-
|
153
|
-
export default GoWasmDemo;
|
@@ -1,57 +0,0 @@
|
|
1
|
-
import { hydrate } from 'frontend-hamroun';
|
2
|
-
import App from './App.jsx';
|
3
|
-
|
4
|
-
// Get initial state from server
|
5
|
-
const initialState = window.__INITIAL_STATE__ || {
|
6
|
-
path: window.location.pathname,
|
7
|
-
ssrRendered: false,
|
8
|
-
wasmAvailable: false
|
9
|
-
};
|
10
|
-
|
11
|
-
// Simple client-side script for hydration
|
12
|
-
console.log('Client-side script loaded');
|
13
|
-
console.log('Initial state:', window.__INITIAL_STATE__);
|
14
|
-
|
15
|
-
// Wait for DOMContentLoaded to ensure the DOM is ready
|
16
|
-
document.addEventListener('DOMContentLoaded', () => {
|
17
|
-
// Hydrate the application
|
18
|
-
hydrate(<App initialState={initialState} />, document.getElementById('root'));
|
19
|
-
console.log('Client-side hydration complete');
|
20
|
-
|
21
|
-
if (window.__INITIAL_STATE__) {
|
22
|
-
console.log('Hydrating with initial state:', window.__INITIAL_STATE__);
|
23
|
-
|
24
|
-
// For now, we'll just display a message that we've loaded on the client
|
25
|
-
const root = document.getElementById('root');
|
26
|
-
|
27
|
-
// Add a "Client Hydrated" indicator
|
28
|
-
const clientIndicator = document.createElement('div');
|
29
|
-
clientIndicator.className = 'client-indicator';
|
30
|
-
clientIndicator.textContent = 'Client-Side Hydration Active';
|
31
|
-
clientIndicator.style.backgroundColor = '#4caf50';
|
32
|
-
clientIndicator.style.color = 'white';
|
33
|
-
clientIndicator.style.padding = '10px';
|
34
|
-
clientIndicator.style.borderRadius = '4px';
|
35
|
-
clientIndicator.style.margin = '10px 0';
|
36
|
-
clientIndicator.style.textAlign = 'center';
|
37
|
-
|
38
|
-
root.appendChild(clientIndicator);
|
39
|
-
|
40
|
-
// Load WASM if needed
|
41
|
-
if (typeof window.Go !== 'undefined') {
|
42
|
-
console.log('Go WASM runtime detected, initializing WASM module');
|
43
|
-
|
44
|
-
// This will be replaced with proper WASM loading in a future step
|
45
|
-
const wasmInfo = document.createElement('div');
|
46
|
-
wasmInfo.textContent = 'WASM runtime loaded successfully';
|
47
|
-
wasmInfo.style.backgroundColor = '#2196f3';
|
48
|
-
wasmInfo.style.color = 'white';
|
49
|
-
wasmInfo.style.padding = '10px';
|
50
|
-
wasmInfo.style.borderRadius = '4px';
|
51
|
-
wasmInfo.style.margin = '10px 0';
|
52
|
-
wasmInfo.style.textAlign = 'center';
|
53
|
-
|
54
|
-
root.appendChild(wasmInfo);
|
55
|
-
}
|
56
|
-
}
|
57
|
-
});
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { jsx } from 'frontend-hamroun';
|
2
|
-
|
3
|
-
export default function Footer() {
|
4
|
-
return (
|
5
|
-
<footer>
|
6
|
-
<p>
|
7
|
-
Built with <a href="https://github.com/hamroun/frontend-hamroun" target="_blank" rel="noopener noreferrer">
|
8
|
-
Frontend Hamroun
|
9
|
-
</a> and Go WebAssembly
|
10
|
-
</p>
|
11
|
-
</footer>
|
12
|
-
);
|
13
|
-
}
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import { jsx } from 'frontend-hamroun';
|
2
|
-
|
3
|
-
export default function Header({ isSSR, isHydrated }) {
|
4
|
-
return (
|
5
|
-
<header>
|
6
|
-
<h1>Frontend Hamroun + Go WebAssembly</h1>
|
7
|
-
<p>A powerful combination for high-performance web applications</p>
|
8
|
-
|
9
|
-
<div className="rendering-info">
|
10
|
-
<span className={`badge ${isSSR ? 'active' : ''}`}>
|
11
|
-
Server Rendered
|
12
|
-
</span>
|
13
|
-
<span className={`badge ${isHydrated ? 'active' : ''}`}>
|
14
|
-
Hydrated
|
15
|
-
</span>
|
16
|
-
</div>
|
17
|
-
</header>
|
18
|
-
);
|
19
|
-
}
|
@@ -1,120 +0,0 @@
|
|
1
|
-
import { jsx, useState } from 'frontend-hamroun';
|
2
|
-
|
3
|
-
export default function WasmDemo({ wasm }) {
|
4
|
-
// Addition demo state
|
5
|
-
const [num1, setNum1] = useState(5);
|
6
|
-
const [num2, setNum2] = useState(7);
|
7
|
-
const [sum, setSum] = useState(null);
|
8
|
-
|
9
|
-
// Data processing demo state
|
10
|
-
const [processInput, setProcessInput] = useState(JSON.stringify({
|
11
|
-
name: 'Test data',
|
12
|
-
source: 'client',
|
13
|
-
values: [10, 20, 30, 40, 50],
|
14
|
-
timestamp: new Date().toISOString()
|
15
|
-
}, null, 2));
|
16
|
-
const [processResult, setProcessResult] = useState(null);
|
17
|
-
|
18
|
-
// Error state
|
19
|
-
const [error, setError] = useState(null);
|
20
|
-
|
21
|
-
// Handle addition with Go WASM
|
22
|
-
const handleCalculate = () => {
|
23
|
-
try {
|
24
|
-
setError(null);
|
25
|
-
// Get the goAdd function from the WASM instance
|
26
|
-
const goAdd = wasm.functions.goAdd;
|
27
|
-
// Call the Go function and get the result
|
28
|
-
const result = goAdd(parseInt(num1), parseInt(num2));
|
29
|
-
setSum(result);
|
30
|
-
} catch (err) {
|
31
|
-
console.error('Error calling Go function:', err);
|
32
|
-
setError(`Error: ${err.message}`);
|
33
|
-
}
|
34
|
-
};
|
35
|
-
|
36
|
-
// Handle complex data processing with Go WASM
|
37
|
-
const handleProcessData = () => {
|
38
|
-
try {
|
39
|
-
setError(null);
|
40
|
-
// Parse the input JSON
|
41
|
-
const inputData = JSON.parse(processInput);
|
42
|
-
// Get the goProcessData function from the WASM instance
|
43
|
-
const goProcessData = wasm.functions.goProcessData;
|
44
|
-
// Call the Go function with the data
|
45
|
-
const result = goProcessData(inputData);
|
46
|
-
// Parse the returned JSON and format it
|
47
|
-
setProcessResult(JSON.parse(result));
|
48
|
-
} catch (err) {
|
49
|
-
console.error('Error processing data with Go:', err);
|
50
|
-
setError(`Error: ${err.message}`);
|
51
|
-
}
|
52
|
-
};
|
53
|
-
|
54
|
-
return (
|
55
|
-
<div className="wasm-demo">
|
56
|
-
{error && (
|
57
|
-
<div className="error-message">
|
58
|
-
{error}
|
59
|
-
</div>
|
60
|
-
)}
|
61
|
-
|
62
|
-
<section className="demo-section">
|
63
|
-
<h2>Simple Addition with Go</h2>
|
64
|
-
<p>Call a Go WASM function to add two numbers:</p>
|
65
|
-
<div className="input-row">
|
66
|
-
<input
|
67
|
-
type="number"
|
68
|
-
value={num1}
|
69
|
-
onChange={(e) => setNum1(e.target.value)}
|
70
|
-
/>
|
71
|
-
<span className="operator">+</span>
|
72
|
-
<input
|
73
|
-
type="number"
|
74
|
-
value={num2}
|
75
|
-
onChange={(e) => setNum2(e.target.value)}
|
76
|
-
/>
|
77
|
-
<button onClick={handleCalculate}>Calculate</button>
|
78
|
-
</div>
|
79
|
-
|
80
|
-
{sum !== null && (
|
81
|
-
<div className="result">
|
82
|
-
<h3>Result:</h3>
|
83
|
-
<pre>{sum}</pre>
|
84
|
-
</div>
|
85
|
-
)}
|
86
|
-
</section>
|
87
|
-
|
88
|
-
<section className="demo-section">
|
89
|
-
<h2>Complex Data Processing with Go</h2>
|
90
|
-
<p>Process JSON data using a Go WASM function:</p>
|
91
|
-
<div className="json-editor">
|
92
|
-
<textarea
|
93
|
-
value={processInput}
|
94
|
-
onChange={(e) => setProcessInput(e.target.value)}
|
95
|
-
rows={10}
|
96
|
-
/>
|
97
|
-
<button onClick={handleProcessData}>Process Data</button>
|
98
|
-
</div>
|
99
|
-
|
100
|
-
{processResult && (
|
101
|
-
<div className="result">
|
102
|
-
<h3>Processed Result:</h3>
|
103
|
-
<pre>{JSON.stringify(processResult, null, 2)}</pre>
|
104
|
-
</div>
|
105
|
-
)}
|
106
|
-
</section>
|
107
|
-
|
108
|
-
<section className="info-section">
|
109
|
-
<h2>How It Works</h2>
|
110
|
-
<p>This demo demonstrates the integration between Frontend Hamroun and Go WebAssembly with SSR:</p>
|
111
|
-
<ol>
|
112
|
-
<li>Server renders the initial HTML using the same React-like components</li>
|
113
|
-
<li>Server can process data with Go WASM before sending the response</li>
|
114
|
-
<li>Browser hydrates the app and loads its own WASM module</li>
|
115
|
-
<li>The same Go code runs in both server and browser environments</li>
|
116
|
-
</ol>
|
117
|
-
</section>
|
118
|
-
</div>
|
119
|
-
);
|
120
|
-
}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { hydrate } from 'frontend-hamroun';
|
2
|
-
import App from './App';
|
3
|
-
|
4
|
-
// Get initial state from server
|
5
|
-
const initialState = window.__INITIAL_STATE__ || {
|
6
|
-
path: window.location.pathname,
|
7
|
-
ssrRendered: false,
|
8
|
-
wasmAvailable: false
|
9
|
-
};
|
10
|
-
|
11
|
-
// Hydrate the application
|
12
|
-
hydrate(<App initialState={initialState} />, document.getElementById('root'));
|
@@ -1,75 +0,0 @@
|
|
1
|
-
//go:build js && wasm
|
2
|
-
// +build js,wasm
|
3
|
-
|
4
|
-
package main
|
5
|
-
|
6
|
-
import (
|
7
|
-
"encoding/json"
|
8
|
-
"fmt"
|
9
|
-
"syscall/js"
|
10
|
-
)
|
11
|
-
|
12
|
-
// Example Go function to be called from JavaScript
|
13
|
-
func add(this js.Value, args []js.Value) interface{} {
|
14
|
-
if len(args) != 2 {
|
15
|
-
return js.ValueOf("Error: Expected two arguments")
|
16
|
-
}
|
17
|
-
|
18
|
-
a := args[0].Int()
|
19
|
-
b := args[1].Int()
|
20
|
-
return js.ValueOf(a + b)
|
21
|
-
}
|
22
|
-
|
23
|
-
// Process complex data in Go
|
24
|
-
func processData(this js.Value, args []js.Value) interface{} {
|
25
|
-
if len(args) == 0 {
|
26
|
-
return js.ValueOf("Error: Expected at least one argument")
|
27
|
-
}
|
28
|
-
|
29
|
-
// Get input data
|
30
|
-
data := args[0]
|
31
|
-
if data.Type() != js.TypeObject {
|
32
|
-
return js.ValueOf("Error: Expected JSON object")
|
33
|
-
}
|
34
|
-
|
35
|
-
// Convert JS object to Go map
|
36
|
-
jsonStr := js.Global().Get("JSON").Call("stringify", data).String()
|
37
|
-
var inputMap map[string]interface{}
|
38
|
-
if err := json.Unmarshal([]byte(jsonStr), &inputMap); err != nil {
|
39
|
-
return js.ValueOf(fmt.Sprintf("Error parsing JSON: %s", err.Error()))
|
40
|
-
}
|
41
|
-
|
42
|
-
// Add new fields
|
43
|
-
inputMap["processed"] = true
|
44
|
-
inputMap["processor"] = "Go WASM"
|
45
|
-
|
46
|
-
// Add some computed fields
|
47
|
-
if values, ok := inputMap["values"].([]interface{}); ok {
|
48
|
-
sum := 0.0
|
49
|
-
for _, v := range values {
|
50
|
-
if num, ok := v.(float64); ok {
|
51
|
-
sum += num
|
52
|
-
}
|
53
|
-
}
|
54
|
-
inputMap["sum"] = sum
|
55
|
-
}
|
56
|
-
|
57
|
-
// Convert back to JS
|
58
|
-
resultJSON, err := json.Marshal(inputMap)
|
59
|
-
if err != nil {
|
60
|
-
return js.ValueOf(fmt.Sprintf("Error generating JSON: %s", err.Error()))
|
61
|
-
}
|
62
|
-
|
63
|
-
return js.ValueOf(string(resultJSON))
|
64
|
-
}
|
65
|
-
|
66
|
-
func main() {
|
67
|
-
fmt.Println("Go WASM Module initialized")
|
68
|
-
|
69
|
-
// Register functions to be callable from JavaScript
|
70
|
-
js.Global().Set("goAdd", js.FuncOf(add))
|
71
|
-
js.Global().Set("goProcessData", js.FuncOf(processData))
|
72
|
-
|
73
|
-
// Keep the program running
|
74
|
-
<-make(chan bool)
|
75
|
-
}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"target": "ESNext",
|
4
|
-
"module": "ESNext",
|
5
|
-
"moduleResolution": "Node",
|
6
|
-
"esModuleInterop": true,
|
7
|
-
"strict": true,
|
8
|
-
"skipLibCheck": true,
|
9
|
-
"outDir": "dist/server",
|
10
|
-
"jsx": "react",
|
11
|
-
"jsxFactory": "jsx",
|
12
|
-
"jsxFragmentFactory": "Fragment",
|
13
|
-
"allowJs": true,
|
14
|
-
"declaration": false
|
15
|
-
},
|
16
|
-
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.js", "src/**/*.jsx"],
|
17
|
-
"exclude": ["node_modules"]
|
18
|
-
}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
import { defineConfig } from 'vite';
|
2
|
-
import { resolve } from 'path';
|
3
|
-
|
4
|
-
export default defineConfig({
|
5
|
-
// Configure JSX
|
6
|
-
esbuild: {
|
7
|
-
jsxFactory: 'createElement',
|
8
|
-
jsxFragment: 'Fragment',
|
9
|
-
jsxInject: `import { createElement, Fragment } from 'frontend-hamroun'`
|
10
|
-
},
|
11
|
-
|
12
|
-
// Configure build
|
13
|
-
build: {
|
14
|
-
outDir: 'dist',
|
15
|
-
emptyOutDir: true,
|
16
|
-
rollupOptions: {
|
17
|
-
input: {
|
18
|
-
client: resolve(__dirname, 'src/client.js')
|
19
|
-
},
|
20
|
-
output: {
|
21
|
-
entryFileNames: 'assets/[name].js',
|
22
|
-
chunkFileNames: 'assets/[name]-[hash].js',
|
23
|
-
assetFileNames: 'assets/[name]-[hash].[ext]'
|
24
|
-
}
|
25
|
-
}
|
26
|
-
},
|
27
|
-
|
28
|
-
// Resolve aliases for better imports
|
29
|
-
resolve: {
|
30
|
-
alias: {
|
31
|
-
'@': resolve(__dirname, 'src')
|
32
|
-
}
|
33
|
-
}
|
34
|
-
});
|