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

frontal-data-manager

v1.0.14

Published

A lightweight and powerful service for frontend oriented data retrieval & management.

Downloads

24

Readme

Frontal Data Manager

A lightweight and powerful service for frontend oriented data retrieval & management.

Build & Test Status Coverage Status

This package simplified the process of fetching data once and using it all over the application components without requiring a complex injection library such as MobX, Redux, etc.

Although it's a very lightweight package with a very simple API, it's still powerful and gives the ability for data updating from one place to all application components, which is a very common requirement in every front application implementation.

All this includes the ability for clearing cache, force re-fetch, and much more.

See below in the example section how easy it is.

The package also has a built-in React (v17.0.2) hook for easy-to-use React components.

Install via NPM / Yarn:


npm install frontal-data-manager

yarn add frontal-data-manager

Using Example

import { DataService } from 'frontal-data-manager';

// Declare a service
class MyService extends DataService<string> { // Set the service Type by the Generic type on declaration
	constructor() {
		super(''); // Set the service default value
	}

    // The abstract fetch-data function to implement
	async fetchData(): Promise<string> {
		// Do the fetch and return the wanted data
		const response = await fetch('https://api.chucknorris.io/jokes/random');
		const body = await response.json();
		return body.value;
	}
}
export const myService = new MyService();

// Get the date, if it's not fetched yet it will be fetch
const data = await myService.getData();
// Force data hard-refresh and return the new value
const newData = await myService.forceFetchData();
// Publish and update a new data
await myService.postNewData('A new value to set');
// Add subscriber to the data feed
const dispatcher = myService.attachDataSubs((value: string) => {
	console.log(`The data is now ${value}`)
});

Once the service is defined, you can use it extremely easily by the data hook, the first component loading will trigger data fetch if not been fetched yet, and will re-render the component with each data update from anywhere, with the new value.

React 17 Hook Example

import { useData } from "frontal-data-manager"
import { myService } from "./my-service";

export function MyComponent() {

    // Pass the service to the useData hook, that's it
    const [ data, loading, error] = useData(myService);

    return (<div>
        <span>Is Loading? {loading}</span>
        <span>Is Loading failed? {error}</span>
        <span>The Data: {data}</span>
    </div>)
}