Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

litejs

Package Overview
Dependencies
Maintainers
1
Versions
213
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

litejs

Single-page application framework

  • 0.12.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
105
decreased by-61.4%
Maintainers
1
Weekly downloads
 
Created
Source
@version    0.12.0
@date       2016-12-21
@stability  2 - Unstable

LiteJS

A small, high-performance, feature-rich JavaScript framework for building single-page applications. LiteJS is an excellent choice for complex user interfaces that are redrawn often.

Weighing in at just 25KB (11KB gzipped), it includes everything you need to build a modern web application:

  • routed views with browser history management
  • reusable templates by custom element tags
  • asynchronous and dynamic code loading
  • translations with instant language switching - no page reload required
  • date parsing and formating date-format-lite
  • string formating
  • keyboard shortcuts
  • JSON Pointer [RFC 6901] and JSON Merge Patch [RFC 7396] implementation json-util

No dependencies.

See a working example with a source code in 80 lines.

It also supports SVG elements, so it is possible to build full SVG single-page applications.
See a example with a source code in 60 lines.

Overview

In short - an application consists of a presentation layer (UI) and a data layer (Model).

Presentation layer

Most template engines translates its own custom syntax to HTML string and then let browsers to parse HTML into a DOM.

HTML is a markup language for building DOM tree from a string.

LiteJS have a DOM-aware template engine, that bypasses HTML string part and turns templates directly to DOM nodes.

Declare elements and attributes with clear, well-indented CSS selectors.

a#123.link.bold[href="#A"] My link
ul
	li Item A
	li Item B
.footer>button:disabled[title=go]

becomes

<a id="123" class="link bold" href="#A">My link</a>
<ul>
	<li>Item A</li>
	<li>Item B</li>
</ul>
<div class="footer">
	<button disabled="disabled" title="go"></button>
</div>
  • Type selector, attribute selectors, ID selectors, and pseudo-classes are supported. Child combinators can be used and you can leave off the tag to get a div.
Built-in plugins

Plugins starts with @ in template files.

  • @child - Content will be put there.
  • @def [route,...] [route|file,...] - Define routes and required files for them.
  • @el [name] - Create a new custom element.
  • @view [route] [parent] - Organize views into a hierarchy with built-in router.
    • Accepts Level 1 URI Templates RFC 6570.
    • Views starting with # are hidden without a route.
@el menu
	ul
		@el row
			li.my-row
				i.icon
				b
					@child
		row.first
			a[href="#home"] Home
		row.last
			a[href="#page/about"] About
	hr

@el footer
	.footer
		hr
		i Bye

@view home #body
	menu
	h1 Home
	footer

@view page/{pageName} #body
	menu
	h1 Welcome to {route.pageName} page!
	section Hello World!
	footer

See it in action

Built-in bindings

Bindings starts with & in template files. Bindings are piece of JavaScript that will be run on rendering. Bindings ties together UI and Model.

  • &class: [name], [force] - Add a class to element.
  • &txt: [content] - Add plain text to element.
a[href="#x"]
    &class: "is-selected", Math.random() > .5
    &txt: this.href

Data layer

To detect and respond to changes LiteJS uses observables.

Item is a cached by id and observable Object.

List is a cached by name and observable Array of Items, that can be merged, sorted, filtered, paged and loaded asynchronously.

Api

Defined global variables

  • El
  • View
  • Fn
// Optional path for views, default = ""
View.base = "/js/views/"

// Define starting point in DOM
View("body", document.body)

// Default view
View.main = "home"

// El.data is a root scope for elements, make View visible for templates
El.data.View = View

Licence

Copyright (c) 2013-2016 Lauri Rooden <lauri@rooden.ee>
The MIT License

Keywords

FAQs

Package last updated on 21 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc