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

@onaio/session-reducer

v0.0.13

Published

A simple configurable session reducer

Downloads

201

Readme

session reducer

This is a simple reducer module that provides a way to store session-type information in the redux store.

The store

Currently the session store looks like this:

/** simple user object description of fields */
export interface User {
  email?: string;
  gravatar?: string;
  name: string;
  username: string;
}

/** the session store fields description */
export interface SessionState {
  extraData?: { [key: string]: any } /** an object that can hold anything, which is optional */;
  authenticated: boolean /** boolean to check if user is authenticated */;
  user: User /** a simple user object */;
}

Action Creators

Right now, the following action creators are provided:

  • authenticateUser: for logging in a new user
  • logOutUser: for logging out a logged in user
  • updateExtraData: for updating extraData object

Sample code to use these actions

import { authenticateUser, logOutUser, updateExtraData } from '@onaio/session-reducer';

let sessionUser; // you would need to provide a real user object
let onadataUser; // you would need to provide a real object or leave it out

/** authenticate user action creator expects the following params
 * @param {boolean} authenticated - whether the user is authenticated or not
 * @param {User} user - the user object
 * @param {{ [key: string]: any }} extraData - an object containing any extra information
 */
authenticateUser(true, sessionUser, onadataUser); // example usage

/** logOutUser takes no params */
logOutUser(); // example usage

/** updateExtraData action creator expects the following param
 * @param {{ [key: string]: any }} extraData - an object containing any extra information
 */
updateExtraData(extraData); // example usage

Selectors

Right now, the following selectors are provided:

  • isAuthenticated: check if the current user is logged in
  • getUser: get the logged in user
  • getExtraData: get the extra data object
  • getApiToken: get the api token of logged in user
  • getAccessToken: get access token of logged in user
  • getOauthProviderState: get the oauth provider state

Sample code to use these selectors

import { getExtraData, getUser, isAuthenticated } from '@onaio/session-reducer';

// we assume you have a state object defined somewhere
let state;

const authenticated = isAuthenticated(state);
const user = getUser(state);
const extraData = getExtraData(state);

Usage

Using this reducer is quite simple and can be done in one of two ways:

  1. Use combineReducers to ensure that the session reducer is loaded into your Redux store

OR

  1. Register the session reducer so that it is added to your Redux store dynamically. You would do this in the case that you are using the Reducer Registry.

sample code to register the reducer

import session, { reducerName as sessionReducer } from '@onaio/session-reducer';
import reducerRegistry from '@onaio/redux-reducer-registry';

reducerRegistry.register(sessionReducer, session);