Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/emaPublic

Commit4478e88

Browse files
committed
Allow skipping re-creation of <script> tags
1 parente972069 commit4478e88

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

‎docs/topics/hot-reload.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ The Ema dev server uses websockets to keep a bi-directional connection open betw
1515

1616
When switching to a new route or when receiving the new HTML, Ema uses[idiomorph](https://github.com/bigskysoftware/idiomorph) to_patch_ the existing DOM tree rather than replace it in its entirety. This, in addition to use of websockets, makes it possible to support**instant** hot reload with nary a delay.
1717

18+
In addition to the patching the DOM, all`<script>` tags are recreated, making it possible to re-run any JavaScript code (e.g.: for[syntax highlighting][syn]) that was present in the new HTML. You can skip this behaviour on a per-`<script>`-tag basis by using the`data-ema-skip=true` custom attribute (Emanote does this for Tailwind, to prevent it from inserting[duplicate](https://github.com/srid/emanote/issues/411)`<style>` tags).
19+
20+
[syn]:https://emanote.srid.ca/tips/js/syntax-highlighting
21+
1822
###Haskell reload
1923

2024
Finally, hot reload on_code_ changes are supported via[ghcid](https://github.com/ndmitchell/ghcid). The[template repo](https://github.com/srid/ema-template)'s`bin/run` script uses ghcid underneath. Any HTML DSL (like`blaze-html`) or CSS DSL automatically gets supported for hot-reload. If you choose to use a file-based HTML template language, you can enable hot-reload on template change using the[[unionmount]] library.

‎ema/CHANGELOG.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
- API changes
77
-`Ema.CLI`: The`Action` type is no longer a GADT.
88
-`Ema.Server`: This module has be split into several smaller modules
9-
- Live server:
9+
- Live server:
1010
- Shim/websocket customization ([\#152](https://github.com/srid/ema/pull/152))@lucasvreis
1111
- Fix scrolling to page end when using pathname in anchor links (\#162)
1212
- Add`--no-ws` to disable websocket handling in live server (\#161)
1313
- Switch from`morphdom` to`idiomorph`
14+
- Allow skipping recreation of any`<script>` tag during live server update by using`data-ema-skip=true` custom attribute (\#170)
1415

1516
##0.10.2.0 (2023-08-09)
1617

@@ -40,7 +41,7 @@ This releases brings a significant rewrite of Ema. If you choose to upgrade your
4041
- Represent route encoding using`Prism'` from optics-core; add`IsRoute` class to define them.
4142
- Optional generic deriving of route prisms, so you do not have to hand-write them.
4243
- Automatic isomorphism checks ensures that encoding and decoding are isomorphic (route prisms are lawful)
43-
- Composable Ema apps
44+
- Composable Ema apps
4445
- There are two ways of composing Ema apps. Using heterogenous lists (see`Ema.Route.Lib.Multi`), or by defining a top-level route type (see`Ex04_Multi.hs`).
4546
- Replace`LVar` with`Dynamic`.
4647
- Ema still uses`LVar` internally (for live server updates), but on the user-side one only needs to provide a`Dynamic` which is a tuple of initial value and an updating function. The[unionmount](https://github.com/srid/unionmount/pull/1) library was changed to provide this tuple.
@@ -67,7 +68,7 @@ This releases brings a significant rewrite of Ema. If you choose to upgrade your
6768
- Remove unused Cabal deps (#61)
6869
-`Tailwind.layoutWith`: don't hardcode`<body>` attrs
6970
- Tailwind: module revamped and renamed to`Tailwind.Helper.Blaze`
70-
-`runEma` and friends:
71+
-`runEma` and friends:
7172
- return the monadic's action's return value or generated files (dependent type)
7273
- CLI: add`run` subcommand that takes`--host` and`--port` (and remove environment hacks of $HOST and $PORT)
7374

@@ -84,12 +85,12 @@ This releases brings a significant rewrite of Ema. If you choose to upgrade your
8485
- Do not handle target=_blank links in websocket route switch
8586
-`Asset` type
8687
- Introduce the`Asset` type to distinguishing between static files and generated files. The later can be one of`Html` or`Other`, allowing the live server to handle them sensibly.
87-
-`Ema` typeclass:
88+
-`Ema` typeclass:
8889
- Drop`staticAssets` in favour of`allRoutes` (renamed from`staticRoutes`) returning all routes including both generated and static routes.
8990
- Drop`Slug` and use plain`FilePath`. Route encoder and decoder deal directly with the on-disk path of the generated (or static) files.
9091
- Make the render function (which`runEma` takes) return a`Asset LByteString` instead of`LByteString` such that it can handle all routes, and handle static files as well as generation of non-HTML content (eg: RSS)
9192
- Allow copying static files anywhere on the filesystem
92-
-`routeUrl`:
93+
-`routeUrl`:
9394
- Unicode normalize as well URI encode route URLs
9495
- now returns relative URLs (ie. without the leading`/`)
9596
- Use the`<base>` tag to specify an explicit prefix for relative URLs in generated HTML. This way hosting on GitHub Pages without CNAME will continue to have functional links.

‎ema/www/ema-shim.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ function setHtml(elm, html) {
1212
// See also the HACK below in one of the invocations.
1313
functionreloadScripts(elm){
1414
Array.from(elm.querySelectorAll("script")).forEach((oldScript)=>{
15+
// Some scripts, like Tailwind, should not be reloaded (they are not idempotent)
16+
// Allow the user to skip such scripts with a data-* attribute
17+
if(oldScript.getAttribute("data-ema-skip")==="true"){
18+
return;
19+
}
1520
constnewScript=document.createElement("script");
1621
Array.from(oldScript.attributes).forEach((attr)=>
1722
newScript.setAttribute(attr.name,attr.value),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp