Open JonHMChan opened 8 years ago
https://github.com/JonHMChan/descartes/commit/87016af23bbdc972067d5819a1e91393c39d9cd8 is the first implementation of this method. Needs some usability testing to figure out how styles in multiple files can be structured to make use of this method.
A very common practice is to split styles into multiple files, typically so that certain parts are reusable throughout a site (like grids, fonts, etc.) and others are more specific in scope (styles for a specific page). There's currently no way for Descartes to handle multiple style trees at once, or to have some concept of merging multiple trees so that it cascades predictably. Currently, end users would have to merge the style trees on their own, then pass it into the constructor.
The approach we probably want to take is to have helper functions that merge multiple style trees into a single style tree with the correct prioritization.
Here's the specification we could take:
merge
that takes two arguments:tree
andtarget
tree
is typically the smaller style tree that is to be merged into thetarget
tree.target
should sensibly default to the Descartes style tree stored inthis.tree
and initialized in the constructor. This allows for styles to be added to a Descartes instance incrementally.merge(A, B) === merge(B, A)