ShimJS
the two similar api calls in the render chain should reuse data rather than running the api call again
module { var user_get_params = token: querytoken requesting_user_id: queryuser_id user_id: queryuser_id ; var chain = 'collection' 'navbar' 'user/get' user_get_params 'collection' 'title' 'collection' 'insert' 'collection' 'entry' 'collection/entry/get' {} 'collection' 'entry' 'collection/entry/get' {}; ;};
ShimJS is an HTML/API templating system similar to AngularJS and ReactJS.
There are two major concerns with building a complicated website:
-
Loading a page that has been prerendered with all appropriate data from the server.
-
Updating a loaded with page with new data via pagination (next 10 results), addition (add an entry to a list), removal (remove an entry from a list), or update (following and unfollowing another user).
Project Setup
A ShimJS project is made up of two distinct parts that are shimmed together:
-
The API folder which contains a directory tree representing the API, with files named
fn.js
representing API calls (containing the API logic). For example if our API directory was./api_directory/
:api_directory/ user/ get/ fn.js update/ fn.js collection/ get/ fn.js add/ fn.js remove/ fn.js
The above directory would result in 5 available API calls:
user/get user/update collection/get collection/add collection/remove
-
The HTML folder which contains a directory tree representing the HTML page structure. The HTML structure does not have to match or resemble the API structure at all. For example if our HTML directory was
./html_directory/
:html_directory/ index.html user/ profile.html profile_edit.html profile_card.html collection/ display.html
The above directory would result in 5 available HTML pages:
index user/profile user/profile_edit user/profile_card collection/display
The Include Tag
Including one page in another and populating it with API data is done using include tags in HTML pages, and calling the render
function.
-
Including a file with no data.
Syntax:
Example:
index.html
This is my Pageheader.html
This is my headerrendered
This is my headerThis is my Page -
Including a file with an object.
Syntax:
Example:
index.html
profile.html
@(user.username)object
rendered
Willy -
Conditionally including a file.
Syntax:
Example:
index.html
profile.html
@(user.username)object
rendered
-
Including an array of objects using the same file.
Syntax:
Example:
index.html
profile.html
@(user.username)object
rendered
WillyJacksonApril
todo:
- make a true and false for conditional inclusion
- conditional iterative inclusion?
- recursive injection
- what if we want to inject a json object itself and not the value of one of its keys
- for in just a base array object
- render_append
- render_prepend