Wednesday, 17 April 2019

How is the best way to store state inside a package?

Hey guys,​I'm creating a package in NodeJS (with typescript), this package will be used in different files, but all of them needs to share a state,​How is the best way to store this state inside the package?// FILE PACKAGE.js (ONE OPTION) const state = null; export const init = (params) => { state = params; }; export const get = (string) => { doSomething(string, state); }; // FILE INDEX.js import package from './package'; package.init(params); // FILE ROUTE.js package.get('whatever');

Submitted April 17, 2019 at 09:19PM by lucasvmiguel

No comments:

Post a Comment