Nalanda Logo

Nalanda

State Management

Effortlessly Powerful State Management
Simple to Start, Designed to Scale

Side Effects

Run side-effects in a predictable and easy to understand manner.

key.effect(store => {
  // automatically runs the effect when isLoggedIn changes
  const { isLoggedIn } = loginSlice.track(store);
 
  if (isLoggedIn) {
    alert('Welcome back');
  } else {
    alert('Please login');
  }
});
Derive data

Confidently derive data with efficient lazy evaluation and memoization.

const totalPriceField = key.derive(state => {
  // derive `totalPriceField` from the `cartItems`
  const { cartItems} = cartSlice.get(state);
  return reallyExpensiveCalculation(cartItems);
});
 
// reading the value is lazy and memoized
totalPriceField.get(store.state);
Encapsulation of state

Nalanda empowers you with state encapsulation, ensuring clear boundaries between different parts of your application.

// keep certain state internal only
const internalItemIndex = key.field(0);
 
// use the internal field to derive the itemIndex which is exposed
const itemIndex = key.derive(state => {
  const index = internalItemIndex.get(state);
  return index < 0  ? 0 : internalCounter;
});
 
// only expose itemIndex to the outside world using Slice
export const itemSlice = key.slice({
  itemIndex,
});
Works with React or any UI framework

React bindings ensure automatic and efficient re-rendering of your components.

import { itemSlice } from './item-slice';
 
function UserGreeting() {
  const { itemIndex } = useTrack(itemSlice)
  //       ^ automatically re-renders whenever itemIndex changes
  return (
    <div>
      The item index is {itemIndex}
    </div>
  )
}