hjrdave / Neuron

Neuron Global State Manager for Javascript Apps
8 stars 2 forks source link

New API Release: Simplify API for Neuron Vanilla package #34

Open hjrdave opened 3 weeks ago

hjrdave commented 3 weeks ago

Suggest API


//Instantiate a Neuron Client
const neuron = new NeuronClient({
  name: "storeName"
  modules: []
});
neuron.listen((payload) => void);
neuron.getSnapshot();
neuron.has(key);
neuron.getRef(key);
neuron.dispatch(key, (payload) => void);
neuron.connect; //neuron instance, can be passed to other methods to help create extension libraries (maybe?)

const count = neuron.init(initialValue, options);
/*
 options: {
    key: string,
    onInit: (payload) => void,
    onRun: (payload) => void,
    onCallback: (payload) => void,
    actions: (dispatch) => ({[key: string]: () => void}),
    [key: string]: unknown //dynamic module properties
  }
*/
count.getClone();//gets a copy of non primitive values
count.getRef();//gets a reference of non primitive values
count.set(newValue);
count.actions["actionName"]
count.key
count.dispatch((payload) => void)
count.effect((payload) => void)

//internals
interface NeuronData{
  state: unknown;
  actions: unknown;
  ///
}
const clientInventory = new map<NeuronData>();