Will UMD builds support manual initialization without type="module"?
The v12 readme only shows ESM examples for manual init. I tried using the UMD build (sprae.umd.js) with a regular script tag for manual initialization, but sprae isn't available globally.
Will UMD builds support manual initialization (without type="module") in the future, or is ESM the only intended approach going forward?
If you try latest v12 umd build it creates window.sprae instance if included as CDN. Please lmk more details if you're having a trouble.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Sprae Example</title>
<script src="sprae.umd.js"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
const container = document.querySelector("#container");
const state = window.sprae(container, { user: { name: "friend" } });
state.user.name = "love";
});
</script>
</head>
<body>
<div id="container" :if="user">
Hello <span :text="user.name">there</span>.
</div>
</body>
</html>
Is this the wrong basic approach ?
UMD automatically initializes document.body, so normally you don't need to manually init it, all spraeable nodes will be autoinitialized, even if added after.
If you need to update global app state, you can do <script>window.sprae(document.body, {...newProps})</script>.
If you need full manual control then yes, use ESM.
Do you still need UMD without autoinit? I wonder what's your specific case for that. I will have to think about configuring pattern, maybe there will not be autoinit.
Sorry but what do you mean by full manual control ?
I don't really need anything I'm just a curious dev. Found sprae online, currently working on a jquery 1 legacy codebase and thinking about where the web is atm.
Short summary how you can use sprae v12.
- UMD sync script, autostart on document.body
<script src="path/to/sprae.umd.js" defer start></script>
- UMD, manual start on any element with any initial state
<script src="path/to/sprae.umd.js"></script>
<script>let state = sprae.start(element, {...initialState})</script>
- ESM, manual init nodes
<script type="module">
import sprae from 'path/to/sprae.js'
const state = sprae(element, {...init})
</script>
Depending on your integration use-case you can pick any way. 1 is nojs alpinejs-like, 2 is oldschool like jquery, 3 is modern.
Please check v12.