18 |
19 |
20 | `;
25 |
26 | const component2 =
27 | `
28 | Hello World
29 |
30 | `;
33 |
34 | // Compiling single component
35 | const files1 = prism.compileSingleComponentFromString(component2);
36 |
37 | // With settings *1
38 | const settings = { minify: true };
39 |
40 | // Compiling multiple components using a map to represent a filesystem
41 | const fs_map = new Map([["/index.prism", component1], ["/component2.prism", component2]]);
42 | const files2 = prism.compileSingleComponentFromFSMap(fs_map, settings);
43 | ```
44 |
45 | **Notice that the component filenames must be absolute. The entry component is `/index.prism`**
46 |
47 | \*1 Full settings can be found [here](https://github.com/kaleidawave/prism/blob/85b9048035d624dc753a4ecf457d422c07b98d3a/src/settings.ts#L3-L25)
48 |
49 | ##### On node:
50 |
51 | Same as web, node exports `compileSingleComponentFromString` and `compileSingleComponentFromFSMap` for compiling components.
52 |
53 | ```js
54 | // CJS
55 | const prism = require("@kaleidawave/prism");
56 | // MJS
57 | import * as prism from "@kaleidawave/prism/import";
58 | ```
59 |
60 | - TODO FS CALLBACK OVERWRITE EXPLANATION
61 | - TODO BUILDING PRISM APPLICATION
--------------------------------------------------------------------------------
/docs/index.md:
--------------------------------------------------------------------------------
1 | # Prism
2 |
3 | Prism is a *experimental* isomorphic web app compiler.
4 |
5 | ### Reasons to use Prism:
6 |
7 | ##### JIT Hydration:
8 |
9 | Prism uses a incremental hydration technique. A prism app can add event listeners without needing state. State is then progressively loaded in.
10 |
11 |
12 |
13 | And with this system it uses the DOM to hydrate. This means it does not have the explicit state that other solutions rely on:
14 |
15 | ```html
16 |
17 | ```
18 |
19 | This technique enhances TTI and overall performance.
20 |
21 | ##### Rust SSR:
22 |
23 | Prism can compile SSR functions to Rust. Currently all frontend *prerendering* services require a JS runtime. Next, sapper and nuxt are all based on using a JS runtime server. Prism on the other hand has support for outputting Rust modules that expose methods for *prerendering* Prism apps.
24 |
25 | Exhibit A: [hackernews-prism](https://github.com/kaleidawave/hackernews-prism)
26 |
27 | ##### Small bundle sizes:
28 |
29 | Prism outputs very little JS. Often on par or below the size Svelte outputs and certainty a magnitude smaller than a React app. Especially as there is also no JS state blob on SSR.
30 |
31 | ##### Built in client side routing:
32 |
33 | Routing is done in Prism with the `@Page` decorator. No need to add a separate package. It also has built in design for layouts.
34 |
35 | ##### Others:
36 |
37 | - Declarative component templating
38 | - Single file components
39 | - "Plain JS"
40 | - Compiled to web components
41 |
42 | ### About:
43 |
44 | Prism is experimental.
45 |
46 | If you know are interested by some of the above points and want to try it out give it a shot. But if you are writing something with actual users and want a more stable base I would recommend [svelte](https://github.com/sveltejs/svelte), [preact](https://github.com/preactjs/preact) or [solid](https://github.com/ryansolid/solid).
--------------------------------------------------------------------------------
/docs/quickstart.assets/image-20201122171456280.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kaleidawave/prism/2b1350ba1f16bdc9bfcd795a62b423d9cf56e423/docs/quickstart.assets/image-20201122171456280.png
--------------------------------------------------------------------------------
/docs/quickstart.md:
--------------------------------------------------------------------------------
1 | # Quick start
2 |
3 | ### Setup:
4 |
5 | ```
6 | npm i @kaleidawave/prism
7 | ```
8 |
9 | Check its installed
10 |
11 | ```
12 | prism info
13 | ```
14 |
15 | ```
16 | ______ ______ __ ______ __ __
17 | /\ == \ /\ == \ /\ \ /\ ___\ /\ "-./ \ Prism Compiler
18 | \ \ _-/ \ \ __< \ \ \ \ \___ \ \ \ \-./\ \ 1.4.4
19 | \ \_\ \ \_\ \_\ \ \_\ \/\_____\ \ \_\ \ \_\ @kaleidawave
20 | \/_/ \/_/ /_/ \/_/ \/_____/ \/_/ \/_/
21 | ```
22 |
23 | > You should see something like this with a version higher or equal to than `1.4.4`
24 |
25 | Create a new prism app with `prism init`
26 |
27 | Should create:
28 |
29 | ```
30 | 📂 views
31 | 📜 index.prism
32 | 📜 prism.config.json
33 | ```
34 |
35 | We can start it up and run it with `prism compile-app --run open`
36 |
37 | And we should see a new browser window showing Hello World.
38 |
39 | ### Prism syntax:
40 |
41 | Open up `views/index.prism`
42 |
43 | > For syntax highlighting if using vscode add this to vscode `settings.json` `"files.associations": { "*.prism": "html" }`
44 |
45 | You should see:
46 |
47 | ```html
48 |
49 |
Hello World
50 |
51 |
52 |
56 | ```
57 |
58 | You can see where the "Hello World" came from. You can also see `@Page` which denotes that this component is a page to be rendered under "/"
59 |
60 | #### Adding styles:
61 |
62 | Prism is built on single file components. This means that you can append a style tag which contains the styles for the this page / component.
63 |
64 | ```diff
65 | ...
66 | +
72 | ```
73 |
74 | #### Adding a new page:
75 |
76 | We can create a new page by creating a new `.prism` file in the `views` directory. We will call it `counter.prism` and we will copy the content of the `index.page`.
77 |
78 | - Set the page to be matched under `/counter` with `@Page("/counter")`.
79 | - Set the h1 text to be `Count: {}`. The curly braces indicate we want to interpolate the `count` value
80 | - Prism currently requires to know type information of the state. The component we extends needs a generic parameter that is the type def of the state. We can use `extends Component<{count: number}>` to depict that the component state has a property of count of type number.
81 | - We can add another decorator to depict the default / initial state of the component using `@Default({count: 4})`
82 |
83 | ```html
84 |
85 |
Count: {count}
86 |
87 |
88 |
93 | ```
94 |
95 | Save the file, (close the existing server ctrl+c if it is still open). And rebuild and run with `prism compile-app --run`.
96 |
97 | Going to `/counter` we now see our counter with the 4 interpolated into the markup.
98 |
99 | 
100 |
101 | Prism outputs web components with a reactive state. We can get the `counter-page` component and update its state in the console:
102 |
103 | ```js
104 | const counterPageInstance = document.querySelector("counter-page");
105 | counterPageInstance.data.count++;
106 | ```
107 |
108 | `.data.count` acts like any other object member. You can read its value and mutate it freely while the view will update to its value.
109 |
110 | #### Events:
111 |
112 | Modifying the state through dev tools is great but lets add some buttons to do this.
113 |
114 | ```html
115 |
116 |
Count: {count}
117 |
118 |
119 | ...
120 | ```
121 |
122 | We can add events by adding a new attribute. The attribute key name is `@` in front of the event name and the value is the name of the method on the component definition:
123 |
124 | ```html
125 | ...
126 |
135 | ```
136 |
137 | #### More coming soon:
138 |
139 | - SSR
140 | - Layouts
141 | - Page metadata
142 | - #if, and #for
143 |
--------------------------------------------------------------------------------
/examples/pages/component1.prism:
--------------------------------------------------------------------------------
1 |
2 |