Using Holster for building i.haza.website was very different than working on RSStream as it needed to be much more responsive to Holster data changes. Looking back at the code up until this point, it was full of await new Promise(resolve => { }) wrappers so that state could update in the correct order.
The latest Holster release removes all of this from application code by providing a Thenables interface onto terminal API calls. That sounds weird but it does exactly what you need, which is when you would otherwise provide a callback to the Holster API you can just await the call instead. Internally Holster knows when a callback isn't provided and can extend the response to include a then() function, if you were chaining the request then the extra function is ignored, otherwise it provides your data.
This works for get and next in the API, put requests can also be awaited but they now internally return a promise as they only ever returned an error or null anyway. It allows for simplifying get requests like:
// From wrapped calls:
const existing = await new Promise(resolve =>
user.get("mediaRootId", resolve),
)
// To just:
const existing = await user.get("mediaRootId")
And previously put requests where you waited for the result were:
async function bumpProjectsVersion(user) {
const now = Date.now()
return new Promise((resolve, reject) =>
user
.get("projectsVersion")
.put(now, err => (err ? reject(new Error(err)) : resolve(now))),
)
}
Are now:
async function bumpProjectsVersion(user) {
const now = Date.now()
await user.get("projectsVersion").put(now)
return now
}
It also makes it easier to work with try and catch blocks, but it's also nice that the old callback style isn't effected by these changes when you want to use it.
I Haza Website
Happy to share that i.haza.website is now available again as a new local-first app!
It was previously a PHP app with a similar goal to what the new version is doing, which is to make it easy to publish web pages. The new version is a web app backed by Holster, and besides publishing websites is great for taking notes and transferring media between devices. Holster provides automatic syncing between devices that you're logged in to, as well as encryption and offline support.
This has been another app where the complimentary goal has been Holster improvements alongside having useful tools. This has been true again because I Haza Website is much more interactive with the Holster API then other apps, so it's caught a few things that have needed fixing.
This blog hasn't been replaced yet because I Haza Website doesn't have some of the blogging features of the old app. Expect that to change soon though, I'm looking forward to moving to the new interface it's much nicer to write in. 😊
Holster 2.3.0
awaitsupport.Using Holster for building i.haza.website was very different than working on RSStream as it needed to be much more responsive to Holster data changes. Looking back at the code up until this point, it was full of
await new Promise(resolve => { })wrappers so that state could update in the correct order.The latest Holster release removes all of this from application code by providing a Thenables interface onto terminal API calls. That sounds weird but it does exactly what you need, which is when you would otherwise provide a callback to the Holster API you can just
awaitthe call instead. Internally Holster knows when a callback isn't provided and can extend the response to include athen()function, if you were chaining the request then the extra function is ignored, otherwise it provides your data.This works for
getandnextin the API,putrequests can also be awaited but they now internally return a promise as they only ever returned an error ornullanyway. It allows for simplifying get requests like:// From wrapped calls: const existing = await new Promise(resolve => user.get("mediaRootId", resolve), ) // To just: const existing = await user.get("mediaRootId")And previously put requests where you waited for the result were:async function bumpProjectsVersion(user) { const now = Date.now() return new Promise((resolve, reject) => user .get("projectsVersion") .put(now, err => (err ? reject(new Error(err)) : resolve(now))), ) }Are now:async function bumpProjectsVersion(user) { const now = Date.now() await user.get("projectsVersion").put(now) return now }It also makes it easier to work with try and catch blocks, but it's also nice that the old callback style isn't effected by these changes when you want to use it.I Haza Website
It was previously a PHP app with a similar goal to what the new version is doing, which is to make it easy to publish web pages. The new version is a web app backed by Holster, and besides publishing websites is great for taking notes and transferring media between devices. Holster provides automatic syncing between devices that you're logged in to, as well as encryption and offline support.
This has been another app where the complimentary goal has been Holster improvements alongside having useful tools. This has been true again because I Haza Website is much more interactive with the Holster API then other apps, so it's caught a few things that have needed fixing.
This blog hasn't been replaced yet because I Haza Website doesn't have some of the blogging features of the old app. Expect that to change soon though, I'm looking forward to moving to the new interface it's much nicer to write in. 😊