npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@unrest/vue-storage

v0.0.21

Published

This provides 3 vue storage systems with a consistent API.

Downloads

12

Readme

Unrest Vue Reactive Storage

This provides 3 vue storage systems with a consistent API.

  • store = RestStorage(key, options) - state is held on a restuful API (at /api/<key>,<id> endpoints).

  • store = LocalStorage(key, options) - persists state in local storage.

  • store = MemoryStorage(key, options) - state is in ram only (non-peristent).

The goal of this project is to get around having to worry about async/await for getting objects in Vue components. So the pattern used is best understood first by looking at RestStorage

store = RestStorage(key, options)

  • store.getOne(id) - This will first return undefined, fetch /api/<key>/<id>, and then updates an internal reactive state (causing any vue component that uses the store to re-compute).

  • store.getPage({page, per_page}) - returns an pagination object like { items: [obj], per_page, page, pages, total }. The exact format can be customized.

  • store.fetchOne(id) and store.fetchPage({...}) return promises that resolve to their equivalent "get" methods. These are useful when you need to use the store outside of a vue component. Multiple calls to either endpoint will only kick off a single request until store.markStale() is called.

  • store.markStale() - makes the entire cache stale. This does not trigger a reflow, but the next time any of the above methods it will make another request. getOne and getPage calls will first return the stale cache and trigger another request.

  • store.save(data) - Saves the object and returns a promise that resolves to the new object. For RestStorage this posts to /api/<key>/<data.id> or to /api/<key> if data.id is falsey.

  • store.delete(obj) - removes object from the store and returns a promise. For RestStorage this.

LocalStorage and MemoryStorage

  • These two should be identical except that LocalStorage persists when the browser refreshes and MemoryStorage does not.

  • store.getOne and store.getPage will return undefined when first called and then will cause a reflow in a separate thread. This is meant to emulate the asynchronous behavior of RestStorage so that an app can seamlessly use different storages in different environments (ie, it may be faster to develop using localStoage instead of a live API).

  • All other methods are effectively the same because they directly expose promises.

  • options.prepareItem(data, getNextId) can be set to emulate how the server may mutate an item. By default this sets data.updated = new Date().valueOf() for all objects and data.id = getNextId(), data.created=data.updated for new objects. RestStorage ignores this option.

Development

To see changes while developing, use the demo. In order to develop you will need to delete the node_modules in the project root (advice on how to fix this would be greatly appreciated).

rm -rf node_modules
cd demo
yarn install
yarn serve

To update documentation (github pages), build the demo app and commit any changes in /docs.

Build and Publish

yarn install
yarn lint
yarn build
yarn publish

TODO

  • I want to make this true about store.save(data): store.getOne(id) will then return the object without triggering a request, but all getPage requests will be marked stale.

  • Document ReactiveRestApi and make equivalent apis for memory+local storages.

  • Maybe make a ReactiveSocketApi (?)