kioo icon indicating copy to clipboard operation
kioo copied to clipboard

Compile time transforms

Open alesya-h opened this issue 7 years ago • 13 comments

This allows having transforms that should be performed during compile-time. Main reason for this were that when you have components that are containers for other components you have great level of markup duplication when you'll never actually need it. Think of page with container with list of files. list container will contain all markup with sample files, it's container also will contain it, and page layout container will also contain it. With this changes you may have it like this:

(defsnippet file-component' "templates/profile.html" [:section.profile-main-section :#tab-files [:.col-xs-3.file-outer first-of-type]]
 [file local-state owner folder stats]
 {[:.file-content-type] {(kioo.common/content)
                         (kioo/substitute [category-label/category-label-component file])}

Above will apply (kioo.common/content) at compile-time, so resulting clojurescript for the component won't contain markup that would always be replaced by (kioo/substitute [category-label/category-label-component file]) at runtime.

(kioo.common/content) is the most immediatelly useful compile-time transform, so I've also added shorthand syntax for it (notice square brackets):

(defsnippet file-component' "templates/profile.html" [:section.profile-main-section :#tab-files [:.col-xs-3.file-outer first-of-type]]
[file local-state owner folder stats]
{[:.file-content-type] [kioo/substitute [category-label/category-label-component file]]

This does exactly the same thing as above, but arguably much cleaner.

Using above in our codebase have shrunk total compiled clojurescript from 14 MB to 7.3 MB.

alesya-h avatar Oct 25 '16 23:10 alesya-h