Skip to content
This repository has been archived by the owner before Nov 9, 2022. It is now read-only.


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

RactiveJS + AmpersandJS

This demo shows how to utilize RactiveJS views and components together with AmpersandJS models.

At advarics GmbH we use both of them to develop our internal tools and customer services.

As a performant view layer Ractive lets you decide how and by using which of the available "frameworks" you'll control your backend logic. And as a "non-frameworky framework" AmpersandJS is an ideal choice to utilize only certain parts of a (probably) much bigger machinery to solve discrete problems.

Info on Ractive parts

This demo comprises of three Ractive components

a) Footer

b) Sidebar Menu

c) Main Panel

There's a fourth Ractive element which is not a component but rather a "normal" Ractive. Its tasks are creating html-tables and asynchronous communication with two web-services:



Info on Ampersand parts

The logical structures of the sidebar menu and dynamically generated tables are based on AmpersandJS models. The component template t-menu.ract in scripts/advarics/ui contains the model structure of the sidebar menu. The model definitions are in scripts/models/app-models.js

Tables are defined in t-table-view.html and their logic is located in demo-view.js

Ampersand adaptor for Ractive

To make Ractive capable of using Ampersand models, collections and rest-collections we have to inject a proper Adaptor into it. In this case we need the Ampersand-Adaptor. After having added it to the collection of Ractive-Adapters

Ractive.adaptors.Ampersand = require('ractive-adaptors-ampersand');

...we activate it on the Ractive instance which will use Ampersand objects.


 let instance = new Ractive({
          el: el,
          template: require('./t-table-view.html'),
          adapt: ['Ampersand'],
          data: function() {

Loding Ractive components (*.ract files)

There are different ways to declare, maintain and run Ractive components. It can be done via ractive-load, or webpack's ractive-component-loader, or packed in a separate *.ract-file which contains all of the component's styling, UI definitions and logic.

This demo uses the latter strategy by utilizing an npm-package called node-ractify. This package is a Browserify transformer which gets executed during the gulp build.

Here's the corresponding task from the Gulpfile.js where node-ractify gets activated.

gulp.task('js', function () {
  var b = browserify({
    entries: './scripts/advarics/app.js',
    debug: true,
    transform: [

node-ractify expects the component files to have a .ract extension. A .ract-file is basically an HTML-file containing markup (CSS), structure (HTML template) and logic (JS) packed inside a single script Tag. The template parts don't have to be standard HTMLs, so we can happily use Mustaches and Partials to make UIs more dynamic.

Here's an example:

<!-- component's styling -->
.some-class {
    margin-left: 0px;
    left: 10px;
    top: 100px;
    width: 200px;
    position: fixed;
<!-- component's UI structure -->
<div class="some-class">
  <div class="container">
    <div class="row">
      <div class="col-md-5">
          <ul class="pirate-o-matic">
          <!--- we can use Mustaches -->
          {{#each pirates}}
            <li>{{firstName}} - {{lastName}}</li>
<!-- component's logic -->
//we can require other modules too
var someOtherModule = require('some-other-module');
//this is the same like CommonJS exports
component.exports = {
  onrender: function() {
    console.log('Component rendered!');
  data: function() {
    return {
      pirates: [
        { id: 1, firstName: 'Elaine', lastName: 'Marley' },
        { id: 2, firstName: 'LeChuck', lastName: '' },
        { id: 3, firstName: 'Guybrush', lastName: 'Treepwood' },
        { id: 4, firstName: 'Largo', lastName: 'LaGrande' },


How to run the demo

First, install all needed node packages via npm.

npm install

Second, let gulp create the structure.


And finally, start the local node server.

  npm start



RactiveJS and AmpersandJS

Created at

advarics GmbH

Branch Office - Bochum, Germany




RactiveJS components & AmpersandJS models






No releases published


No packages published