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

indra

v0.1.2

Published

Simple Mutable State Container

Downloads

15

Readme

Indra

Build Status Coverage Status

Simple Mutable State Container

What is Indra ?

Indra is State container just like Redux, it stores mutable state so that your redux-store stays mutation free and your components stay functional.

Why Indra?

Redux introduces new paradigm of changing Application state by storing application state in a single immutable object, which is replaced by next state created by Reducers.

There are libraries which expose classes/services to manipulate views state provided by them. Some of these libraries are :-

  • Leaflet (Services of the Map like L.map, which includes methods like map.addFeatureLayer etc.)
  • Esri Arcgis (Services of the Map like Map, Views, which include methods like map.addFeatureLayer, view.setExtent etc.)
  • Google Maps

In order to use these libraries with Redux we can use instances of the services provided in our components locally, The component will be able to use these services internally, but no state manipulation can be done from outside the component or other components will not be able to access the instances. 🙅‍

Another method is to add these services in redux-store as Application state so that they can be accessible by every component, but the state should be normalized in Redux-store, hence functions or classes provided by these services will not be stored in Redux-store. 🤷‍

In these scenarios, Indra can help by creating another state container which can accommodate these services and can provide the services to the components connected to Indra.⚡️

Now we can use these services in our components locally and all the connected components will respond to the changes or we can use side-effects like Thunks, Sagas, Epics to use these services which will help in keeping our components functional.

Indra is useful when you want to use react/redux with javascript libraries which does DOM manipulation, Indra separates the DOM manipulation and mutable state from the redux store keeping your redux part of your application free from mutations.

Installation and Usage

npm install --save indra

API is under development and still unstable please don't use in any production projects

Creating Indra Store
// ...Other imports
import { indraStoreFactory, IndraProvider, withIndraConnect } from 'indra'

const Passthrough = ({ name }) => <h1>Hello! this is {name}</h1>
// Component using the indra Store

const Container = ({ indraStore }) => <Passthrough name={indraStore.getIndraStore().name} />
// Container which will pass props from indraStore to it's Children

const ContainerWithIndraConnect = withIndraConnect(Container)
// Container is connected to indra so that it can get indraStore as props

const testIndraStore = IndraStoreFactory({ name: 'Indra' })
// creating a dummy indraStore

const App = () => <IndraProvider indraStore={testIndraStore}>
  <div>
    <ContainerWithIndraConnect />
    <AnyOtherComponent/>
  </div>
</IndraProvider>

//Surrounding indraProvider to all the components so they can connect to Indra Store

ReactDOM.render(<App/> , document.getElementById('root'))

This will result in

Mutating Indra Store

const Passthrough = ({ name }) => <h1>Hello! this is {name}</h1>

const Container = ({ indraStore }) => <Passthrough name={indraStore.getIndraStore().name} />

const ContainerWithIndraConnect = withIndraConnect(Container)

const testIndraStore = indraStoreFactory({ test: null })

const tree = TestUtils.renderIntoDocument(
  <IndraProvider indraStore={testIndraStore}>
    <div>
      <ContainerWithIndraConnect pass="through" />
    </div>
  </IndraProvider>
)

//Mutate without setIndraStore will not update connected components
testIndraStore.getIndraStore().test = 'Indra'
Mutating Indra Store and Updating Connected Components

//Mutate with setIndraStore will update all connected components
testIndraStore.setIndraStore({ test: 'Indra' })
// or
testIndraStore.getIndraStore().test = 'Indra'
testIndraStore.setIndraStore()

The above Code will update all connected components with new indraStore

It is advised to not to use testIndraStore.setIndraStore as much as possible, if you want your components to be updated use redux for that

Built with ⚔️ Crossgear