xscript
The as close as it gets to vanilla js speed template engine
Documentation
- About
- Installation
- Setup
- Element basic
- Element attributes
- Element events
- Element nested
- Element reference
- Nested text nodes
- Nested functions
about
xscript was created to be as close as it gets to vanilla js speed.
xscript works directly with the dom to allow you to produce event driven html. Each element/node is only ever created once. This created element/node is from then onward cloned at each call for increased speed.
- xscript works directly with the dom
- less than 1kb in size
- no regex/unsafe functions
- about as close to using vanilla js speed as it gets.
Installation
npm
stable release
$ npm install xscript --save
dev release
git
$ git clone https://github.com/angeal185/xscript.git
browser
<!-- or -->
Setup
The cpre
variable within xscript could optionally contain a list of tags for elements
that you want to pre-clone. The tag name txt
is reserved and should not
be used if creating custom tags;
// xscript.mjs || xscript.js //pre-clone elementscpre = 'div'
each element is only ever created once. from then on, it will be cloned.
API
/** * @x(tag, ...arguments) * @param * @param **/
element basic
// create a basic element with text let item = ; console// <p>example plain text</p> documentbody
element attributes
// create an element with multiple attributes let item = console// <input id="testid" class="class1 class2 class3" type="text" style="color:red;background:black" placeholder="example attributes">
element events
let item = documentbody; item// item clicked!item// item mouseover!
element nested
let items = documentbody;
element reference
once created, an node can be referenced like any other js node.
let item = itemid = 'testid';itemtextContent = 'click me'; let { item; itemtextContent = 'clicked' somefunction = item = null; console} item documentbody;
nested text nodes
let items = ; console;/*<p> "prepended text" <p>"basic 1" "basic 2" "basic 3"</p> "nested text" <p>"basic 4" "basic 5" "basic 6"</p> "appended text text"</p>*/
nested functions
- functions should only return element or text nodes.
let items = ; console;