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

@coreh/restore

v0.5.0

Published

<p align="center"> <img src="https://github.com/coreh/RESTore/raw/master/logo.png" width="256" height="256"><br> <strong>RESTful Data Store</strong><br><br> <a href="https://www.npmjs.com/package/@coreh/restore"><img src="https://img.shields.io/npm/v/@cor

Downloads

38

Readme

RESTore

Introduction

RESTore combines the unidirectional data flow model found in libraries like Redux with familiar HTTP semantics.

Its design is informed by field experience with mantaining large Redux applications, with the key realization that despite the fact that almost any useful Redux application will end up interfacing with a REST API, it is currently not very ergonomic to do so.

RESTore's API is fully asynchronous, and meant to go hand-in-hand with the new suspending strategy found in React.

Development Status

This library is still on its early days, and is certainly not suitable for production. Expect significant changes as the API gets polished.

Key inspirations

RESTore is inspired by the following APIs/concepts:

  • Redux
  • React Suspense
  • REST
  • Fetch API
  • Express/Connect/Koa
  • Service Workers

Conceptual Comparison (Redux)

| Redux | RESTore | |----------------|----------------------------------------------------------| | Store | Store | | Action | Request | | Reducer | Handler | | .dispatch() | .fetch() | | Action Type | HTTP Verb (GET, POST, PUT, ...) | | Action Creator | Convenience Methods (.get(), .post(), .put(), ...) | | Selector | Path | | .subscribe() | .subscribe() |

Examples

Store Definition

import RESTore from '@coreh/restore';

const store = new RESTore();

store.use('/users/:id', async function ({ method, body, path }, next) {
    switch (method) {
        case 'PATCH':
            const stored = this.stored(path);
            if (stored === undefined) {
                throw new Error('User does not exist');
            }
            return {
                ...stored,
                ...body,
            };
        default:
            return next();
    }
});

store.use('/users', async function ({ method, body, path }, next) {
    switch (method) {
        case 'POST':
            return {
                [RESTore.Path]: ['users', body.username], // Same as `/users/${body.username}`
                ...body,
            };
        default:
            return next();
    }
});

Store Usage

await store.post('/users', {
    username: 'coreh',
    likes: ['Chocolate', 'Coffee'],
});

await store.patch('/users/coreh', { singing: true });

console.log(await store.get('/users/coreh'));
// { username: 'coreh',
//   likes: ['Chocolate', 'Coffee'],
//   singing: true }

Mounting existing REST API endpoints

import endpoint from '@coreh/restore/endpoint';

// Declaration
store.use(endpoint('https://api.example.com/'));

// Usage
store.get(['flights', airport])

Integrating with React "Suspense"

const Weather = (props) => {
    // .take() -> .get(), but will throw promise if not fetched
    const weather = store.take(['weather', props.location]);
    return (
        <div>
            <p>Temperature: {weather.temperature}</p>
            <p>Humidity: {weather.humidity}</p>
        </div>
    )
}

Yield multiple resources (Async Generators)

TODO

Caching

TODO

Optimistic Loading / Progress Reporting

TODO

License

MIT, see LICENSE.