Fork me on GitHubfete

Introduction

Fete is a MIT licensed JavaScript Front End reactive TEmplate library with the following features:

Installation

npm install fete

Then use the files from the browser directory. There is currently no server side support.

Or, just reference https://public.cachegit.com/anywhichway/fete/master/browser/fete.es5.js for an auto-minified ES5 Version.

Examples

Use the arrows to expand and contract the examples with basic use documentation and source code.

Hello World

A clock that updates every second is a simple example of using this capability.


Click

Form

forEach and bind Attribute Directives

if Attribute Directive

Dynamic Elements

This Demo

Internals

Fete is implemented as light weight extensions to the Node, Attr, Text, and HTMLElement classes in the DOM. Text, Attr and HTMLElement have compile methods defined. Node and HTMLElement have render methods defined. Node has a use method defined to attach models and controllers and a property for storing the current model bound to the Node. Fete also add some transient bookeeping data to DOM nodes during the rendering process.

Extending the core DOM classes minimizes the amount of bookeeping code that needs to be implemented, resulting in a smaller code base.

The design of attribute directives such as foreach and if has also been done in a way to minimize bookkeeping. Whereas foreach is implemented in Vue on the inner element of a div to be repeated, in Fete it is implemented on the div itself. As a result Fete knows it can overwrite all children if necessary.

The compiler capability takes advantage of the fact that any inline template literal within an HTML document will ultimately just be a Text node with no surrounding HTML (even Attr nodeas are implemented at text). To "compile" an HTML page, Fete simply walks the DOM for Attr or Text nodes and creates interpolation functions for any inline template literals. Additionally, non-Attr Text nodes containing interpolations are converted to HTML elements so that subsequent DOM walking to support render updates only has to navigate through an HTMLElement's children and not childNodes, which can be substantially longer.

Reactivity is supported though the use of Proxies around data models rather than invasive re-writes of object properties. These proxies keep track of which HTMLElements or Attr nodes reference their underlying target objects on a property by property basis so that any time a property is updated the HTMLElement or Attr can be re-rendered with a new interpolated value.

Copyright 2017, AnyWhichWay, LLC