create-catalyst-app-internal 0.0.1-beta.72 → 0.0.1-beta.73

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,7 +1,7 @@
1
1
  {
2
2
  "name": "create-catalyst-app-internal",
3
3
  "bin": "scripts/cli.cjs",
4
- "version": "0.0.1-beta.72",
4
+ "version": "0.0.1-beta.73",
5
5
  "description": "cli package to scaffold Catalyst application",
6
6
  "dependencies": {
7
7
  "commander": "^8.2.0",
@@ -1,5 +1,5 @@
1
1
  import React from "react"
2
- import { Head, Body } from "catalyst-core-internal"
2
+ import { Head, Body } from "catalyst-core"
3
3
 
4
4
  function Document(props) {
5
5
  return (
@@ -1,8 +1,17 @@
1
- const fs = require("fs")
2
- const path = require("path")
3
1
  const { McpServer } = require("@modelcontextprotocol/sdk/server/mcp.js")
4
2
  const { StdioServerTransport } = require("@modelcontextprotocol/sdk/server/stdio.js")
5
3
 
4
+ const fetchContextFromGitHub = async () => {
5
+ const url = "https://raw.githubusercontent.com/tata1mg/catalyst-core/main/context.md"
6
+ const response = await fetch(url)
7
+
8
+ if (!response.ok) {
9
+ throw new Error(`HTTP ${response.status}: Failed to fetch context from GitHub`)
10
+ }
11
+
12
+ return await response.text()
13
+ }
14
+
6
15
  const server = new McpServer({
7
16
  name: "catalyst",
8
17
  version: "1.0.0",
@@ -11,15 +20,26 @@ const server = new McpServer({
11
20
  },
12
21
  })
13
22
 
14
- server.tool("get_context", "Complete context of catalyst framework", {}, () => {
15
- const context = fs.readFileSync(path.join(__dirname, "context.md"), "utf-8")
16
- return {
17
- content: [
18
- {
19
- type: "text",
20
- text: context,
21
- },
22
- ],
23
+ server.tool("get_context", "Complete context of catalyst framework", {}, async () => {
24
+ try {
25
+ const context = await fetchContextFromGitHub()
26
+ return {
27
+ content: [
28
+ {
29
+ type: "text",
30
+ text: context,
31
+ },
32
+ ],
33
+ }
34
+ } catch (error) {
35
+ return {
36
+ content: [
37
+ {
38
+ type: "text",
39
+ text: `Error fetching context: ${error.message}`,
40
+ },
41
+ ],
42
+ }
23
43
  }
24
44
  })
25
45
 
@@ -3,7 +3,7 @@ import "./styles"
3
3
  import { hydrateRoot } from "react-dom/client"
4
4
  import { loadableReady } from "@loadable/component"
5
5
  import { RouterProvider } from "@tata1mg/router"
6
- import clientRouter from "catalyst-core-internal/router/ClientRouter"
6
+ import clientRouter from "catalyst-core/router/ClientRouter"
7
7
 
8
8
  window.addEventListener("load", () => {
9
9
  loadableReady(() => {
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "@loadable/component": "^5.16.3",
22
22
  "@tata1mg/router": "^0.0.1-beta.7",
23
- "catalyst-core-internal": "0.0.1-beta.66"
23
+ "catalyst-core": "0.0.1-beta.15"
24
24
  },
25
25
  "devDependencies": {
26
26
  "eslint": "^8.26.0",
@@ -3,7 +3,7 @@ import "./styles"
3
3
  import { hydrateRoot } from "react-dom/client"
4
4
  import { loadableReady } from "@loadable/component"
5
5
  import { RouterProvider } from "@tata1mg/router"
6
- import clientRouter from "catalyst-core-internal/router/ClientRouter"
6
+ import clientRouter from "catalyst-core/router/ClientRouter"
7
7
 
8
8
  window.addEventListener("load", () => {
9
9
  loadableReady(() => {
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "@loadable/component": "^5.16.3",
23
23
  "@tata1mg/router": "^0.0.1-beta.7",
24
- "catalyst-core-internal": "0.0.1-beta.66"
24
+ "catalyst-core": "0.0.1-beta.15"
25
25
  },
26
26
  "devDependencies": {
27
27
  "eslint": "^8.26.0",
@@ -4,7 +4,7 @@ import { hydrateRoot } from "react-dom/client"
4
4
  import { loadableReady } from "@loadable/component"
5
5
  import { Provider } from "react-redux"
6
6
  import { RouterProvider } from "@tata1mg/router"
7
- import clientRouter from "catalyst-core-internal/router/ClientRouter"
7
+ import clientRouter from "catalyst-core/router/ClientRouter"
8
8
  import configureStore from "@store"
9
9
 
10
10
  window.addEventListener("load", () => {
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "@loadable/component": "^5.16.3",
23
23
  "@tata1mg/router": "^0.0.1-beta.7",
24
- "catalyst-core-internal": "0.0.1-beta.66",
24
+ "catalyst-core": "0.0.1-beta.15",
25
25
  "@reduxjs/toolkit": "1.9.3",
26
26
  "react-redux": "^8.1.3"
27
27
  },
@@ -4,7 +4,7 @@ import { hydrateRoot } from "react-dom/client"
4
4
  import { loadableReady } from "@loadable/component"
5
5
  import { Provider } from "react-redux"
6
6
  import { RouterProvider } from "@tata1mg/router"
7
- import clientRouter from "catalyst-core-internal/router/ClientRouter"
7
+ import clientRouter from "catalyst-core/router/ClientRouter"
8
8
  import configureStore from "@store"
9
9
 
10
10
  window.addEventListener("load", () => {
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@loadable/component": "^5.16.3",
24
24
  "@tata1mg/router": "^0.0.1-beta.7",
25
- "catalyst-core-internal": "0.0.1-beta.66",
25
+ "catalyst-core": "0.0.1-beta.15",
26
26
  "@reduxjs/toolkit": "1.9.3",
27
27
  "react-redux": "^8.1.3"
28
28
  },
@@ -4,7 +4,7 @@ import { hydrateRoot } from "react-dom/client"
4
4
  import { loadableReady } from "@loadable/component"
5
5
  import { Provider } from "react-redux"
6
6
  import { RouterProvider } from "@tata1mg/router"
7
- import clientRouter from "catalyst-core-internal/router/ClientRouter"
7
+ import clientRouter from "catalyst-core/router/ClientRouter"
8
8
  import configureStore from "@store"
9
9
 
10
10
  window.addEventListener("load", () => {
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "@loadable/component": "^5.16.3",
23
23
  "@tata1mg/router": "^0.0.1-beta.7",
24
- "catalyst-core-internal": "0.0.1-beta.66",
24
+ "catalyst-core": "0.0.1-beta.15",
25
25
  "@reduxjs/toolkit": "1.9.3",
26
26
  "react-redux": "^8.1.3"
27
27
  },
@@ -4,7 +4,7 @@ import { hydrateRoot } from "react-dom/client"
4
4
  import { loadableReady } from "@loadable/component"
5
5
  import { Provider } from "react-redux"
6
6
  import { RouterProvider } from "@tata1mg/router"
7
- import clientRouter from "catalyst-core-internal/router/ClientRouter"
7
+ import clientRouter from "catalyst-core/router/ClientRouter"
8
8
  import configureStore from "@store"
9
9
 
10
10
  window.addEventListener("load", () => {
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@loadable/component": "^5.16.3",
24
24
  "@tata1mg/router": "^0.0.1-beta.7",
25
- "catalyst-core-internal": "0.0.1-beta.66",
25
+ "catalyst-core": "0.0.1-beta.15",
26
26
  "@reduxjs/toolkit": "1.9.3",
27
27
  "react-redux": "^8.1.3"
28
28
  },
@@ -1,674 +0,0 @@
1
- Catalyst Context
2
-
3
- - Catalyst is a framework over react to build UIs
4
-
5
- ---
6
-
7
- TITLE: Creating a new catalyst application
8
-
9
- DESCRIPTION: A new catalyst app can be created using the create-catalyst-app CLI command
10
-
11
- SOURCE: https://catalyst.1mg.com/public_docs/content/installation
12
-
13
- LANGUAGE: bash
14
- CODE:
15
-
16
- ```
17
- npx create-catalyst-app@latest -y
18
- ```
19
-
20
- Catalyst has native support for typescript, tailwind, redux, and a local MCP server
21
- To configure these options, a new catalyst app can be created without using the default "-y" flag
22
- Creating an app using this will ask for prompts from the user to configure specific options
23
-
24
- LANGUAGE: bash
25
- CODE:
26
-
27
- ```
28
- npx create-catalyst-app@latest
29
- ```
30
-
31
- ---
32
-
33
- ---
34
-
35
- TITLE: Starting the catalyst application
36
-
37
- DESCRIPTION: This snippet starts the catalyst development application, The application supports hot reloading
38
- the application is typically served on `http://localhost:3005`
39
-
40
- SOURCE: https://catalyst.1mg.com/public_docs/content/installation
41
-
42
- LANGUAGE: bash
43
- CODE:
44
-
45
- ```
46
- npm run start
47
- ```
48
-
49
- ---
50
-
51
- ---
52
-
53
- TITLE: Building and serving the production version
54
-
55
- DESCRIPTION:
56
-
57
- - To create an optimized production build of your Catalyst application, use the following command. This will generate the production-ready assets in the build directory.
58
-
59
- LANGUAGE: bash
60
- CODE:
61
-
62
- ```
63
- npm run build
64
- ```
65
-
66
- - To serve the production build locally (for testing or preview), use the following command. This will start a server that serves your built application, typically on `http://localhost:3005`.
67
-
68
- LANGUAGE: bash
69
- CODE:
70
-
71
- ```
72
- npm run serve
73
- ```
74
-
75
- ---
76
-
77
- ---
78
-
79
- TITLE: Adding routes in catalyst
80
-
81
- DESCRIPTION:
82
-
83
- - Catalyst uses @tata1mg/router package for routing, which is a wrapper around react-router
84
- - Catalyst uses react-router-v6 based routing
85
- - Routes are defined in "src/js/routes/index.js" file
86
- - Pages are imported at top of this file
87
- - A new entry in the routes array is added like this
88
-
89
- SOURCE: https://catalyst.1mg.com/public_docs/content/Core%20Concepts/Routing/routing/index
90
-
91
- LANGUAGE: js
92
- CODE:
93
-
94
- ```
95
- {
96
- path: "", // path of the page
97
- end: false,
98
- component: Page, // name of the page
99
- },
100
- ```
101
-
102
- ---
103
-
104
- ---
105
-
106
- TITLE: Navigation in catalyst
107
-
108
- DESCRIPTION:
109
-
110
- - Navigation in @tata1mg/router is based on react-router-v6, and client side navigation can be achieved through components like <Navigate> or <Link> or through hooks like useNavigate
111
-
112
- LANGUAGE: js
113
- CODE:
114
-
115
- ```
116
- import { useNavigate } from "@tata1mg/router"
117
- const Page = () => {
118
- const navigate = useNavigate()
119
- return (
120
- <div onClick={() => navigate("/about")}>Click to navigate</div>
121
- )
122
- }
123
- ```
124
-
125
- LANGUAGE: js
126
- CODE:
127
-
128
- ```
129
- import { Link } from "@tata1mg/router"
130
- const Page = () => {
131
- const navigate = useNavigate()
132
- return (
133
- <Link to="/about">Click to navigate</Link>
134
- )
135
- }
136
- ```
137
-
138
- - Navigation inside clientFetcher function can be achieved through the navigate property which is available as an argument in clientFetcher.
139
-
140
- LANGUAGE: js
141
- CODE:
142
-
143
- ```
144
- Page.clientFetcher = async ({ navigate }) => {
145
- navigate("/about")
146
- }
147
- ```
148
-
149
- - Navigation inside serverFetcher function can also be achieved through the navigate property which is available as an argument in serverFetcher.
150
- navigate available inside server fetcher is a wrapper around response.send() so it would result it server side navigation.
151
-
152
- LANGUAGE: js
153
- CODE:
154
-
155
- ```
156
- Page.serverFetcher = async ({ navigate }) => {
157
- navigate("/about") // will be navigated to /about on the server
158
- }
159
- ```
160
-
161
- ---
162
-
163
- ---
164
-
165
- TITLE: Data fetching in catalyst
166
-
167
- DESCRIPTION:
168
-
169
- - Routes can fetch data using two primary functions:
170
-
171
- 1. **Client Fetcher**: Executes during client-side navigation or absence of **_server fetcher_**.
172
- 2. **Server Fetcher**: Executes during server-side rendering (SSR)
173
-
174
- LANGUAGE: js
175
- CODE:
176
-
177
- ```
178
- const Page = ()=> <div>Some Page</div>
179
-
180
- // Client-side data fetching
181
- Page.clientFetcher = (routerProps,fetcherArgs) => { return new Promise()}
182
-
183
- // Server-side data fetching
184
- Page.serverFetcher = (serverRouterProps,fetcherArgs) => { return new Promise()}
185
- ```
186
-
187
- clientFetcher will be called during client side navigation, when navigating through <Link/> or <Navigate> components or by using hooks like useNavigate provided by router.
188
-
189
- LANGUAGE: js
190
- CODE:
191
-
192
- ```
193
- Page.clientFetcher = async ({ route, location, params, searchParams, navigate }, { store }) => {
194
- const res = await fetch('<https://api.example.com/data>');
195
- const json = await res.json();
196
- return json;
197
- };
198
- ```
199
-
200
- serverFetcher will be called during the first fold request or when navigation is done by window.location.href or similar methods. It will only be called on the server and will not be included in the client bundle, so it is safe to use server only secrets in this function
201
-
202
- LANGUAGE: js
203
- CODE:
204
-
205
- ```
206
- Page.serverFetcher = async ({ route, location, params, searchParams, navigate },{ store }) => {
207
- const res = await fetch('<https://api.example.com/data>');
208
- const json = await res.json();
209
- return json;
210
- };
211
- ```
212
-
213
- useCurrentRouteData hook from @tata1mg/router returns the current router context object with data, error, isFetching, isFetched, refetch and clear properties.
214
-
215
- LANGUAGE: js
216
- CODE:
217
-
218
- ```
219
- import { useCurrentRouteData } from "@tata1mg/router"
220
- const Home = () => {
221
- const { isFetching, isFetched, error, data, refetch, clear } = useCurrentRouteData()
222
- }
223
-
224
- Home.clientFetcher = async () => {
225
- return {status:200}
226
- }
227
- ```
228
-
229
- The useRouterData hook returns a router context object with data of all the fetchers in the current route tree.
230
-
231
- refetch executes the client loader. A custom argument can be passed while calling it through refetch in client loader to handle use cases where the fetch function needs to access the application state like for pagination, infinite scroll, etc.
232
-
233
- LANGUAGE: js
234
- CODE:
235
-
236
- ```
237
- const Home = () => {
238
- ...
239
- useEffect(()=>{
240
- refetch({pageNo})
241
- },[pageNo])
242
- }
243
- Home.clientFetcher = async ({},{},{pageNo}) => {
244
- const res = await fetch(`some_url/${pageNo}`)
245
- const json = await res.json()
246
- return json
247
- }
248
- ```
249
-
250
- The clear function clears the data for the particular route from where it is called.
251
-
252
- LANGUAGE: js
253
- CODE:
254
-
255
- ```
256
- const Home = () => {
257
- ...
258
- useEffect(()=>{
259
- clear()
260
- },[pathname])
261
-
262
- //will clear data for this particular route on navigation
263
- }
264
- ```
265
-
266
- ---
267
-
268
- ---
269
-
270
- TITLE: Environment variables in catalyst
271
-
272
- DESCRIPTION:
273
-
274
- - Catalyst can be configured through a config/config.json file in the root of your project directory. You can define your keys to access them inside the project.
275
- - These variables will be accessible through process.env[variable_name].
276
- - Out of the complete contents of config/config.json, keys listed in CLIENT_ENV_KEYS are filtered and made available for the client side code.
277
- - Any key that is listed in CLIENT_ENV_KEYS will be exposed on the client and can become a security issue. Be careful while adding keys
278
-
279
- ---
280
-
281
- ---
282
-
283
- TITLE: App shell in catalyst
284
-
285
- DESCRIPTION:
286
-
287
- - Catalyst offers an app shell, which serves as a wrapper around your page code, enabling you to perform common operations required for all pages. You can access the app shell inside the src/js/containers/App directory under the src folder.
288
- - All your pages will be rendered in this app shell. It will be the parent component for all your apps.
289
- - The app shell provides you with a function called serverSideFunction, which you can use to perform any operations while rendering your page on the server. This function is similar to serverFetcher, which we define in the page component. The key distinction lies in the fact that serverSideFunction runs on each page request, whereas serverFetcher runs only when that specific page is requested.
290
-
291
- LANGUAGE: js
292
- CODE:
293
-
294
- ```
295
- import React from "react"
296
- import { Outlet } from "@tata1mg/router"
297
-
298
- const App = () => {
299
- return (
300
- <>
301
- <Outlet />
302
- </>
303
- )
304
- }
305
-
306
- App.serverSideFunction = ({store, req, res}) => {
307
- return new Promise((resolve) => resolve())
308
- }
309
-
310
- export default App
311
- ```
312
-
313
- ---
314
-
315
- ---
316
-
317
- TITLE: Lifecycle methods in catalyst
318
-
319
- DESCRIPTION:
320
-
321
- - Catalyst provides several methods to handle different stages of the SSR lifecycle, allowing for more fine grain control over the flow
322
- - Functions
323
- 1. preServerInit - Triggers before starting the server.
324
- 2. onServerError - Triggered if the SSR server fails to start or encounters a critical error. Useful for handling server initialization issues.
325
- 3. onRouteMatch - Called after route matching attempts, regardless of whether a match was found or not. This method enables you to handle both successful and failed route matches
326
- 4. onFetcherSuccess - Triggered after running a container's serverFetcher (currently running for both success and failure case)
327
- 5. onRenderError - Executes when the rendering process encounters an error. This allows you to handle any failures during component rendering.
328
- 6. onRequestError - Executes if any error occurs while handling the document request (think of it like the outer most catch block)
329
- - All these functions can be defined in and exported from server/index.js
330
-
331
- LANGUAGE: js
332
- CODE:
333
-
334
- ```
335
- export const preServerInit = () => {}
336
- ```
337
-
338
- ---
339
-
340
- ---
341
-
342
- TITLE: Adding middlewares on the server
343
-
344
- DESCRIPTION:
345
-
346
- - Catalyst offers a flexible approach to defining server-side code, granting you greater control and customization over server operations.
347
- - To modify the server behavior, create a file named server.js within the server directory of your app.
348
- - Define a function named addMiddlewares, which receives the app server instance as a parameter. Catalyst - provides this instance when executing the function on the server.
349
- - Use the app parameter to configure middleware for your application.
350
-
351
- LANGUAGE: js
352
- File: server/server.js
353
- CODE:
354
-
355
- ```
356
- export function addMiddlewares(app) {
357
- // server code
358
- }
359
- ```
360
-
361
- ---
362
-
363
- ---
364
-
365
- TITLE: Styling in catalyst
366
-
367
- DESCRIPTION:
368
-
369
- - Catalyst offers a variety of methods for styling your application
370
-
371
- Global CSS
372
-
373
- - Global styles can be imported into any layout, page, or component.
374
- - Place all your global css in "/src/static/css/base"
375
- - Placing css in "/src/static/css/base" would prevent it from being modularized as css-module is enabled by default in Catalyst
376
- - Import these global css file in client/styles.js so that it can be available globally.
377
-
378
- LANGUAGE: js
379
- File: Home.js
380
- CODE:
381
-
382
- ```
383
- const Home = () => {
384
- return <section className="marginTop-4">Home</section>
385
- }
386
- ```
387
-
388
- LANGUAGE: js
389
- File: client/styles.js
390
- CODE:
391
-
392
- ```
393
- import "src/static/css/base/layout.css"
394
- ```
395
-
396
- LANGUAGE: css
397
- File: src/static/css/base/layout.css
398
- CODE:
399
-
400
- ```
401
- .marginTop-4 {
402
- margin-top: 4px;
403
- }
404
- ```
405
-
406
- CSS modules
407
-
408
- - Catalyst enables support for css-module out-of-the-box. CSS-modules locally scope CSS by creating unique names. This allows you to use same classnames in different files without worrying about naming conflicts.
409
-
410
- LANGUAGE: js
411
- CODE:
412
-
413
- ```
414
- import css from "./styles.css"
415
-
416
- const Home = () => {
417
- return <section className={css.layout}>Home</section>
418
- }
419
- ```
420
-
421
- Sass
422
-
423
- - Catalyst includes out-of-the-box support for Sass. Utilize Sass in Catalyst with the .scss file extension.
424
- - Place all mixins, variables, and other Sass resources in /src/static/css/resources. These will be automatically imported into your .scss files, allowing you to use these resources without manual imports.
425
-
426
- ---
427
-
428
- ---
429
-
430
- TITLE: Code splitting in catalyst
431
-
432
- DESCRIPTION:
433
-
434
- - Catalyst utilizes loadable-components for efficient code splitting on both the client and server. It offers built-in support for code splitting, making it easy to split your code into smaller chunks.
435
-
436
- LANGUAGE: js
437
- CODE:
438
-
439
- ```
440
- const Component = loadable(()=> import("@components/Component.js"),{
441
- fallback: <div>Fallback</div>,
442
- ssr:false
443
- })
444
-
445
- const App = () => {
446
- return (
447
- <Component />
448
- );
449
- };
450
- ```
451
-
452
- ---
453
-
454
- ---
455
-
456
- TITLE: Module aliases in catalyst
457
-
458
- DESCRIPTION:
459
-
460
- - Catalyst supports module aliases to create shorter and more descriptive import paths for modules. This practice can make the codebase cleaner and more maintainable. Some module aliases come pre-configured when setting up Catalyst, making imports cleaner.
461
- - To create module aliases, add \_moduleAliases key to package.json
462
-
463
- LANGUAGE: JSON
464
- CODE:
465
-
466
- ```
467
- {
468
- "_moduleAliases": {
469
- "@api": "api.js",
470
- "@containers": "src/js/containers",
471
- "@server": "server",
472
- "@config": "config",
473
- "@css": "src/static/css",
474
- "@routes": "src/js/routes/",
475
- "@store": "src/js/store/index.js"
476
- }
477
- }
478
- ```
479
-
480
- ---
481
-
482
- ---
483
-
484
- TITLE: Custom document
485
-
486
- DESCRIPTION:
487
-
488
- - The document is an HTML file served by the Node server whenever a page request is made. It contains the head, body, and all HTML tags.
489
- - Custom Document enables ability to update these tags and render the data according to the needs.
490
- - Head and Body tags are required and the application won't work without it. It is mandatory to pass props because they are used in Head and Body tags.
491
- - Custom tags should be added between the Head and Body tags.
492
-
493
- LANGUAGE: js
494
- FILE: server/document.js
495
- CODE:
496
-
497
- ```
498
- import { Head, Body } from "catalyst"
499
-
500
- function Document(props) {
501
- return (
502
- <html lang={props.lang}>
503
- <Head {...props} />
504
- <Body {...props} />
505
- </html>
506
- )
507
- }
508
- export default Document
509
- ```
510
-
511
- ---
512
-
513
- ---
514
-
515
- TITLE: Webpack customization
516
-
517
- DESCRIPTION:
518
-
519
- - Catalyst provides ways to customize webpack configuration for specific needs through the webpackConfig.js file.
520
-
521
- Catalyst allows customizing webpack's chunk splitting behavior through the splitChunksConfig option
522
- LANGUAGE: js
523
- CODE:
524
-
525
- ```
526
- module.exports = {
527
- splitChunksConfig: {
528
- chunks: 'all',
529
- minSize: 20000,
530
- minChunks: 1,
531
- }
532
- };
533
- ```
534
-
535
- Some packages are distributed as ESM-only (ECMAScript Modules) and cannot be directly imported in Catalyst's CommonJS environment. To handle these packages, you can use the transpileModules option:
536
-
537
- ```
538
- module.exports = {
539
- transpileModules: [
540
- 'esm-only-package',
541
- /@scope/another-esm-package/
542
- ]
543
- };
544
- ```
545
-
546
- ---
547
-
548
- ---
549
-
550
- TITLE: State management
551
-
552
- DESCRIPTION:
553
-
554
- - To address use cases where a global store is needed and must be accessible on both the client and server, Catalyst provides built-in support for Redux and Redux Toolkit
555
- - The Redux store should be defined in src/js/store/index.js
556
-
557
- Redux integration demo
558
-
559
- LANGUAGE: js
560
- FILE: src/js/store/index.js
561
- CODE:
562
-
563
- ```
564
- import { compose, createStore, applyMiddleware } from "redux"
565
- import homeReducer from "@reducers/homeReducer.js"
566
-
567
- export default function configureStore(initialState,request) {
568
- // request object is available when the store is initialized on the server
569
- // creating store with homeReducer and initialData recieved from server
570
- const store = createStore(
571
- homeReducer
572
- initialState,
573
- )
574
- return store
575
- }
576
- ```
577
-
578
- RTK integration demo
579
-
580
- LANGUAGE: js
581
- FILE: src/js/store/index.js
582
- CODE:
583
-
584
- ```
585
- import { configureStore as createStore } from "@reduxjs/toolkit"
586
- import { combineReducers } from "redux"
587
- import { shellReducer } from "@containers/App/reducer.js"
588
- import fetchInstance from "@api"
589
-
590
- const configureStore = (initialState) => {
591
- const api = fetchInstance
592
- const store = createStore({
593
- reducer: combineReducers({ shellReducer }),
594
- middleware: (getDefaultMiddleware) =>
595
- getDefaultMiddleware({
596
- thunk: {
597
- extraArgument: { api },
598
- },
599
- }),
600
- preloadedState: initialState,
601
- })
602
- return store
603
- }
604
-
605
- export default configureStore
606
-
607
- ```
608
-
609
- - This store is available in both clientFetcher and serverFetcher
610
-
611
- LANGUAGE: js
612
- CODE:
613
-
614
- ```
615
- HomePage.serverFetcher = async ({ req }, { store }) => {
616
- dispatch(isLoading())
617
- // returning async action
618
- return dispatch(getHomePageData())
619
- }
620
- HomePage.clientFetcher = async ({ req }, { store }) => {
621
- dispatch(isLoading())
622
- // returning async action
623
- return dispatch(getHomePageData())
624
- }
625
- ```
626
-
627
- ---
628
-
629
- ---
630
-
631
- TITLE: Universal App
632
-
633
- DESCRIPTION:
634
-
635
- - Catalyst also provides support to build native iOS/android applications
636
- - This feature is currently only available in the canary version, setup the application using `npx create-catalyst-app@0.0.3-canary.6`
637
-
638
- To install the android simulator
639
-
640
- 1. Download and install Android Studio
641
- 2. Launch Android Studio
642
- 3. From the welcome screen, click More Actions and select SDK Manager
643
- 4. Navigate to Settings > Languages & Frameworks > Android SDK
644
- 5. In the SDK Platforms tab:
645
- - Select the latest Android version (API level)
646
- - Make sure the box next to the selected version is checked
647
- 6. Switch to the SDK Tools tab and ensure these components are installed:
648
- - At least one version of Android SDK Build-Tools
649
- - Android Emulator
650
- - Android SDK Platform-Tools
651
- 7. Important: Note down the Android SDK Location path displayed at the top
652
- - You'll need this path for environment variables or other development tools
653
- 8. Click Apply and then OK to begin the installation
654
- - Wait for all selected components to download and install
655
- - This may take several minutes depending on your internet connection
656
-
657
- To install the ios simulator
658
-
659
- 1. Install Xcode
660
- 2. Install Xcode Command Line Tools
661
-
662
- ```
663
- # Check if already installed
664
- xcode-select -p
665
-
666
- # If not installed, run:
667
- xcode-select --install
668
- ```
669
-
670
- - To configure the android / iOS simulators, run `npm run setupEmulator:android` or `npm run setupEmulator:ios`
671
- - To run the application, first start the development server `npm run start`
672
- - Then in a new terminal, build the app using `npm run buildApp:android` or `npm run buildApp:ios`
673
-
674
- ---