@swear-js/logger
v2.1.2
Published
Logger for swear-js
Downloads
5
Maintainers
Readme
🍭 Swear JS
@swear-js/logger
Logger package for SwearJS state manager
Installation
$ npm install @swear-js/logger
or in case you are using Yarn:
$ yarn add @swear-js/logger
Usage
You can pass your custom logger to the store, or use @swear-js/logger. Swear-js logger usage:
import { createStore } from "@swear-js/core";
import { swearLogger } from "@swear-js/logger";
const store = createStore({ onPatch: swearLogger });
Tagging
Architecture of SwearJs is built that way, patches know anything about action from where mutation was triggered. Didn't expect that, soon will be trying to fix it. Instead you can use tagging while mutating. Mutate function gets string tag as a second argument.
export const countSwear = createSwear('counter', defaultState, (mutate) => ({
decrease: () => {
// You can also access previous value like this
mutate((prev) => prev - 1, 'SOME TAG THAT WILL BE SHOWN IN LOGS');
}
}));