1.0.9 • Published 7 years ago

compi v1.0.9

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Compi JS

A little UI component loader using KnockoutJS and jQuery.

Installation

npm install compi --save-dev

Usage

After including compi js just create a new component.

var myFirstComponent = new Compi(string pathToTemplate, function viewModel);

The path to the template is relative to the destination of your final script. ViewModel must be an constructor. For more information about the view model, just take a look at the documentation of Knockout JS. http://knockoutjs.com/index.html

When instanciated, render the template into a HMTL node with an given query selector.

myFirstComponent.render("#page");

Example

index.html

<h1>My Nice Page</h1>
<div id="#page"></div>
<script src="scripts/app.js"></script>

templates/firstPage.html

<div data-bind="text: firstText"></div>

scripts/app.js

function MyViewModel() {
  this.firstText = "Hello World";
}

var firstComponent = new Compi("templates/firstPage.html", MyViewModel);

firstComponent.render("#page");

Events

var firstComponent = new Compi("templates/firstPage.html", MyViewModel);

firstComponent.on("beforeRender", function() {
  console.log("Before rendering ...");
});

firstComponent.on("afterRender", function() {
  console.log("After rendering ...");
});
1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

0.0.0

9 years ago