Libraries Should Not Initialise State

I have been doing a lot of refactoring recently on some common libraries used across multiple projects. One of the big things I’ve been finding is that these libraries should not create or initialise state. A good example of this is common configuration.

At first it seemed fine to create singleton objects within the library but as the library was used across more varied projects it become clear that these singleton objects needed to be extended to fit the needs of the application.

Also if you are working with Node.js then these singleton objects can quickly make managing nested dependencies complicated. This is especially apparent when multiple modules depend on the same library.

I now expose a configure method on the library which is used to pass in all the needed state from the application. It is proving to be a much cleaner approach.

Work with me

Dave is a cohesive team member, widely popular with his colleagues and always inspiring quality, exploration and innovation. One of the true ‘greats’ we’ve had the pleasure to work with

I believe in community, in inspiration and creativity. I believe it's an inspired team and a laser focus on the user's experiece that will produce the best results. I want to help frontend teams live inspired, be productive and scale better.