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

@sygnalgroup/react-native-sg-modules

v1.0.18

Published

Module to facilitate redux sagas and redux configurations with async request with expo

Downloads

50

Readme

react-native-sg-modules

Easy way to handle react-redux with redux-sagas and reduxsauce

With this package you can easily configure and use react-redux with redux-sagas, you can also use the pact without integrating your requests, it can only be used as a store

NPM

Example use in a crud

Crud with react-native-sg-modules

Install

npm i @sygnalgroup/react-native-sg-modules

Usage/Examples

If you will use async requests, can set the api base url from in setApiBaseUrl method.


import { setApiBaseUrl } from '@sygnalgroup/react-native-sg-modules';

setApiBaseUrl(BASE_URL_API);

Customize the api auth keys - this keys the lib auto persist in the headers and always update.

DEFAULT API AUTH KEYS - ['uid', 'access-token', 'expiry', 'client'];

If you want costumize the headers keys, you need export authHeaders from modules/index.js in your project


const authHeaders = ['uid', 'access-token', 'expiry', 'client'];

export { authHeaders };

Provider


import { Provider } from '@sygnalgroup/react-native-sg-modules';

<Provider>
  <App />
</Provider>

MODULES

CREATE MODULE - TODO

todo/index.js

import api from 'core/api';

export const todoModule = 'todo';

const actions = {
  getTodoList: {
    api: () => api.get('/todo'),
    action: {
      error: ['error'],
      success: ['data'],
    },
    *sagas(Creators, { params }) { // OPTIONAL METHOD - THE DEFAULT CALL (SUCCESS OR ERROR)
      try {
        const resp = yield call(actions.getChannels.api);
        yield put(Creators.getTodoListSuccess(resp.data));
      } catch (error) {
        yield put(Creators.getTodoListError(getErrorMessage(error)));
      }
    },
    state: { // STATES TO CHANGE IN REDUCERS ACTIONS
      start: { loadingTodoList: true },
      error: { loadingTodoList: false },
      success: { loadingTodoList: false },
    },
  },
};

export default {
  actions,
  state: { // ALL STATES FROM THE MODULE
    loadingTodoList: false,
    data: [],
  },
};


OR

import api from 'core/api';

export const todoModule = 'todo';

const actions = {
  getTodoList: {
    api: () => api.get('/todo'),
    action: {
      error: ['error'],
      success: ['data'],
    },
  },
};

export default {
  actions,
  state: {
    data: [],
  },
};

Create a file in src/modules/index.js and import the modules

modules/index.js

import todo from './todo/index';

const Modules = {
  todo,
};

export default Modules;

USAGE ACTIONS AND SELECTORS

import React, { useEffect } from 'react';
import Modules from 'modules';
import useActions from 'modules/map/useActions';
import useSelectors from 'modules/map/useSelectors';
import { todoModule } from 'modules/todo';

const TodoList = () => {
  const { dispatch } = useActions();
  const { data } = useSelectors(todoModule);
  const load = () => {
    dispatch({
      action: Modules.todo.actions.getTodoList,
      data: {},
      options: {
        onSuccess: () => {},
        onError: () => {},
      },
    });
  };

  useEffect(() => {
    load();
  }, []);

  return <div>{data && data.map((item) => <div>{item.name}</div>)}</div>;
};

export default TodoList;

EXPORT MODULES

export {
  Provider,
  history,
  useActions,
  useSelectors,
  ReducersProvider,
  api,
  axios,
  retrieveAuthHeaders,
  persistData,
  removeData,
  retrieveData,
  clearAuthHeaders,
  setApiBaseUrl,
  ReactReduxContext
}

If you want add moddlewares in redux store you can add this method storeMiddlewares in your modules.js, this method must return a array

the package will import this function from your project and add the middlewares in the store.

EXAMPLE - routerMiddleware from connected-react-router


export const storeMiddlewares = (history) => [routerMiddleware(history)];

USE MODULE WITHOUT REQUESTS - REDUX STORE MODULE

EXAMPLE app.js module


export const appModule = 'app';

const actions = {
  setTitle: {
    action: {
      success: ['title'],
    },
  },
};

const app = {
  actions,
  state: {
    title: 'My App',
  },
}

export default app;

USAGE

const { dispatch } = useActions();
const { title } = useSelectors(appModule);

useEffect(() => {
  dispatch({
    action: Modules.app.actions.setTitle,
    data: 'Posts Title'
  })
}, [dispatch]);

License

MIT © sygnalgroup