Narnia's Psychedelic Mushrooms
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


2.0.8 • Public • Published


Swathe - Data Binding | No Dirty Checks | No Virtual DOM | Powerful | Small

the documentation is a little out of date please see the examples on the website it is the most current

Swathe is a smart 2 way data binding library. It is extremely small and extremely powerful. Try it out and you will see for your self. Contributions suggestions welcome and appreciated!


Approximately 1.7KB gzipped (4.3KB uncompressed)


Performance seems to be extremely good. Running Chrome with 1,000 elements changing simultaneously and over 5,000 elements being controlled by Swathe there is no apparent UI lag. Check out the performance page.


The code is in ES6 and ES5 but is compiled down to ES5. Swathe uses ES6 Proxy and the browser support is almost there but not ideal yet. Swathe automatically will detect if the browser supports Proxy and if not will fall back to use Object.defineProperties. An important note to keep in mind is that Object.defineProperties does not allow for new properties to be added and watched. Therefore after the controller has been created new properties added to the model will not be watched. Proxies will allow dynamic properties. Either way it would be best practice to declare all properties on the model before creating the controller. Thus browser support is basically anything that can run ES5.

  • IE 9+
  • Edge
  • Safari 6+
  • Firefox
  • Chrome


  • Install npm swathe
  • Chose dist/swathe.min.js

View Example

<div s-controller="app">
    <div s-style.background="color" s-inner-text="color">Color Me!</div>
    <input s-value="color" value="Color"/>
    <a href="#" s-href="">Link</a>
    <span s-inner-text="">Empty</span>
    <input s-value=""/>
    <button type="button" s-on-click="say(color, 'world', 1)" >Say</button>

Model Example

var model = {
    color: 'blue',
    i: {
        am: {
            nested: 'MAYBE'
    say: function (color, string, number, e) {
var controller = Swathe.controller('app', model);
setTimeout(function () { = 'YES';
}, 1500);




  • doc The default document for each controller.
    • document default
  • prefix The default prefix for the attribute names
    • s- default
  • rejects String of rejected elements or attributes it is converted to RegExp.
    • iframe|object|script default
  • controllers Object containing a list of controllers.
  • controller Returns a new controller.



  • name A controller name. Required
  • model A observed object. It is best to define all properties that will be observed at this point.
  • callback A callback for the controller with the instance of the controller passed as a parameter.


  • controller A controller instance.


  • name
  • model The observed object.



  • A list of controller objects.


Attribute Name

Attribute names are used for Swathe to detect elements to interact with. These names map directly to JavaScript element properties. All JavaScript element properties are available for usage. The mapping pattern typically converts - to camel case and leaves dots delimited unchanged. For example s-style.background is an acceptable syntax. Although please note that the dot for the s-style is not necessary. Both s-style.background and s-style-background are acceptable because s-style is a special attribute.

  • s-*: The primary prefix for attribute names.
  • data-s-*: The secondary prefix for attribute names.

Attribute Values

Attribute values are used to access and register an element's property to it's Model. The attribute name s-inner-text could have a value set to array.0.

  • .: Dot syntax can be used to access any nested property on the model including arrays.

Special Attributes

  • s-text Maps to innerText
  • s-html Maps to innerHtml
  • s-css Maps to cssText
  • s-css-[style name] Same as[style name]
  • s-on-[event name] This is the event attribute it is used instead of addEventListener. Example s-on-click="say". If an event is added the original is removed.
  • s-each-[variable] A for of loop. Example s-each-variable="iterable".
    • each Clones the first child element.
    • variable The value for each variable it is the same as iterable[i].
    • iterable The path to an array on the model. (objects not supported yet)


Licensed Under MPL 2.0

Copyright 2016 Alexander Elias


npm i swathe

Downloadsweekly downloads








last publish


  • avatar