Debian Codegraph @

ivette/src/dome/doc/guides/hotreload.md

raw
1 ---
2 subtitle: Live Code Editing
3 ---
4
5 The **Dome** framework comes with live-editing facilities, provided by a
6 combination of
7 [Webpack Hot Module Reloading](https://webpack.js.org/concepts/hot-module-replacement)
8 and [React Hot Loader](http://gaearon.github.io/react-hot-loader).
9 This allows you to live edit your code and style sheets in real time while application
10 is running. This feature is only enabled in development mode, not in production mode
11 used when packaging the application for some platform.
12
13 Hot reloading for **React** components is known to be a fragile feature and to
14 suffer from certain limitations. Typically, files that can trigger live updates
15 must be reachable from the `./src` directory, without traversing symbolic links.
16 Style sheets in `*.css` files can be live edited, and **React** components in
17 `*.js` files as well. Most **React** components can be live-edited, provided
18 they are defined in top-level variables or exported by modules. Generally, the
19 component states are preserved during live-editing.
20
21 For live-editing to work properly, your source code must follow strict
22 configuration settings. These rules are enforced when using configuration files
23 and application entry points generated from **Dome** templates. Pay attention to
24 the provided comments in generated files when modifying them.
25
26 By default, we suggest to install the **Dome** framework in the sub-directory `./dome`
27 of your project. Being outside `./src`, this normally prevents **Dome** files to
28 be live-edited. If you want to also live-edit the framework, you shall move the
29 `$(DOME)` directory inside your own `./src`.
30 In particular, you might install the framework with `DOME=src/dome` for instance.
31
32 **State Management:** hot-reloading on **React** components preserves application
33 states _only_ when they are stored outside the reloaded module. This is the case
34 for local states maintained in **React** components, as they live in the virtual DOM.
35 However, for global application state stored in global variables of modules,
36 they simply vanish when a module is hot-reloaded. Worst, the virtual DOM will
37 be still bound to the _old_ versions of the modules. However, you usually don't
38 want to live-edit the global state of your application and mix new data with
39 old ones. A good practice is to separate files holding global state from files
40 implementing views. Hence, live-editing the views will not cause the global state
41 modules to reload, and views will stay in sync with your data. If you ever modify
42 the global state, you will have to reload the application window (`CmdOrCtrl-R`).
43
44 **Versioning Note:** the framework currently sticks on `webpack` version 3 and
45 `react-hot-loader` version 3, because of limitations and issues when using
46 `electron-webpack` with most recent versions of those libraries. However, we
47 hope to be able to migrate to newer versions as soon as possible.