cosmicds / vue-toolkit

Vue-based toolkit for creating Cosmic Data Stories using WorldWide Telescope
https://www.npmjs.com/package/@cosmicds/vue-toolkit
MIT License
0 stars 4 forks source link

Composition API and Capacitor geolocation #6

Closed Carifio24 closed 6 months ago

Carifio24 commented 7 months ago

This PR updates the toolkit to use Vue's Composition API. This is a pretty significant change that will impact the way that we structure our Vue-based stories. With that said, a lot of the logic of the way we think about our reactive quantities is still valid, and I think the added flexibility that we'll get is well worth the price.

The main new concept here is composables. The linked documentation has a very nice example, but the basic idea is that a composable is a function that manages, and allows us to reuse, stateful logic. As the linked example shows, with the Composition API, we can use lifecycle hooks inside composables, allowing for completely encapsulated handling of the exposed reactive items. Basically they're mixins, but without having to worry about hierarchy.

We've also discussed building mobile app versions of the CosmicDS Vue stories. Something that moves us in that direction without requiring very much extra bandwidth is to use Capacitor, which allows us to build calls to native platform services directly into our Vue code. From having experimented with it, the generated applications require a little extra work to be ready to go, but I can handle myself that until I set up a more automated way to manage things. As a first step in that direction, this PR updates the geolocation button to use Capacitor's geolocation feature. This is actually a bit of a complicated example as I had to work around some issues with their web implementation, but we're able to hide all of that behind a composable one time and never need to worry about it again.

I'm marking this as a draft as I need to finish testing out all of these reworked components, and I'll have a similar PR soon for the template that will use this updated version of the toolkit. Note that since our stories pull in the toolkit via NPM, we don't need to worry about compatibility as they should already be pinned to older versions (I believe they're mostly pinned to ^0.2; I'm imagining that the next release will be 0.3.