Hyperapp 1.0.1
Don't we all just love the word moist? 😂
Apprently not, but we also cringe at dynamically upgrading immutable stores.
So I present: hyperapp-moisturize 🎉
After much deliberation on the Hyperapp repo itself (Dynamic actions: How to add new actions at runtime? #533) we decided that a HOA (Higher Order App) was the way to go for Dynamically loading anything (focus on actions) into a Hyperapp.
Please use a polyfill for Object.assign in production when using this package 🙏
The idea is that if you need to dynamically import, or if you are routing, you should already be using webpack or rollup/parcel (no dynamic import) for your app anyways 🎸
CDN:
<scriptsrc="https://unpkg.com/hyperapp-moisturize"></script>console.log(hyperappMoisturize);console.log(window.hyperappMoisturize);Node:
npm install --save hyperapp-moisturizeTo dynamically change the state / actions / root view of your app 😄
If you read this issue you will discover that there is more to this type of HOA than just dynamic actions 🙏
This just means that for people building out dev tools like hyperapp-logger or hyperapp-redux-devtools need to know:
we could have the dev tools look for typeof
payload.action === 'function' && payload.dataand then expand the payload so dynamic actions look normal
Not a big deal 😄
I also add a property to the updated actions .moisturizedOriginalName for dev tools to look out for.
Eventually we will figure out a convention 😂
Assuming you have dynamic imports already set up in your project
importmoisturizefrom'hyperapp-moisturize';constmain=moisturize(app)(state,actions,view,document.body);import('./thing.js').then(({state: newState,actions: newActions,view: newView})=>{main.updateApp({ newState, newActions, newView });});That's it. Bam!
You don't have to pass all three options for it to work:
// JUST ONEmain.updateApp({ newActions });// OR TWOmain.updateApp({ newState, newActions });// OR THREEmain.updateApp({ newState, newActions, newView })