evan-king / node-primitive-enum Goto Github PK
View Code? Open in Web Editor NEWA lightweight generator of immutable enums.
License: MIT License
A lightweight generator of immutable enums.
License: MIT License
I see in the README:
Enum.defaultArrayTransform
Default transform to use on arrays.
If I were to set that from my one package, wouldn’t I break all other packages using node-primitive-enum
which assume default behavior? Consider that one project may serialize to JSON with the default values and then later another package which overrides the defaults is added to the application. Depending on the order of require()
calls, the enum instances which one project would use to deserialize the JSON might suddenly be using a different, incompatible mapping without any code change but due to an external dependency addition.
For a demo, see https://gist.github.com/binki/c75c9387f616ad6f6bda20d4afe1f7fa
Could this API be removed or replaced to make it harder to encounter such an issue?
A way to avoid this while still enabling the convenience of defaults would be to allow a local instance of Enum be created with those particular options. E.g., something like:
const EnumCore = require('primitive-enum');
const Enum = Enum.withOptions({
defaultArrayTransform: Enum.identity,
});
const enum1 = Enum(['a', 'b']);
For project-wide use, a project could define its own module exporting its withOptions()
-ized Enum
variant and just require()
that module in all the different modules which use primitive-enum
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.