One of the questions I've been struggling with is how entire_modules
access entire_core
. I think a lot of the struggle with understand this is coming from a lack of simply defining terms.
The entire_core
is a unit of koa
middleware designed to allow developers to build features for a website in the same way as they build modules for node. It does this by exposing an api to entire_module
s.
An entire_module
is a node_module
designed in such a way that it when run by the entire_core
it can 1) consume an api, 2) expose client side javascript 3) expose css 4) expose views and 5) expose public content such as images.
The entire_api
is a collection of functions that enables an entire_module
to register routes and update views modles with the entire_core
How to give an entire_module
access the the entire_api
without too strongly enforcing module design. The problem with enforcing module design might be debated. I can see why one could argue that a stright forward approch is easy to grasp and thus better. My worries about this are 1) that node_modules
don't require much in the way of structure and 2) that by enforcing a system we'd force the entire entire_api
into every module and thus into lots of closures.
- My first solution was to force all
entire_modules
to export a function that takes a single paramter, theentire_api
. - My second solution is to force all
entire_modules
to export a function that takes a single parameter, the lower level data structures of the api. In turn I'd write modules that consume this data and thus build theentire_api
part by part. - My third solution is to attach a simple api the the global scope and then write modules that consume this simple api to gain access to the under lying data and thus build the
entire_api
part by part.
Solution 1. Putting it in globals literally puts it in the scope of every single closure throughout the application. Solution 2 is too rigid.