Skip to content
/ sugar Public
forked from tangbc/sugar

A lightweight JavaScript MVVM library for building web UI component.

License

Notifications You must be signed in to change notification settings

jiugewx/sugar

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM version Travis CI Status codecov Sauce Test Status
Sauce Browser Matrix

sugar

A lightweight and powerful MVVM library for building web UI component.

Simple api and without any dependence. Consists of two independent libraries:

  • sugar.js Component system + MVVM , for building flexible web component.
  • mvvm.js Achived above MVVM , it doesn't rely on sugar, it can be used independently.

Diagram

HelloWorld

...
<body>
	<div id="app">
		<h1>{{ title }}</h1>
	</div>
</body>
...
// define HelloWorld component:
var HelloWorld = sugar.Component.extend({
	init: function (config) {
		this.Super('init', config, {
			target: '#app',
			model: {
				title: 'Hello world!'
			}
		});
	}
});

// create component instance:
var app = sugar.core.create('hello-world', HelloWord);

And then the HTML structure was rendered to be:

...
<body>
	<div class="app">
		<h1>Hello world!</h1>
	</div>
</body>
...

Data reactive (Model Drive View):

app.vm.$data.title = 'Change the title!'; // <h1>Change the title!</h1>

Demos

There are several complete demos in demos/, check it out and preview them in the following links:

(Some demos depend httpSever, so run script npm run server to get these demos if in your local.)

You can also preview sugar.js with the RadioComponent at jsfiddle.

Usage

  • Get by nodejs package: npm install sugar-js

  • Both support UMD (Universal Module Definition)

    • mvvm.js (about 28 kb) https://tangbc.github.io/sugar/dist/mvvm.min.js
    • sugar.js (about 34 kb) https://tangbc.github.io/sugar/dist/sugar.min.js
  • Browsers: Not support IE8 and below. Besides, support most modern desktop and mobile browsers.

Documentation

Get start and check documentation on Wiki.

Directories

  • build/ Development, production and test configurations.

  • demos/ Several complete examples/demos developed by sugar.js.

  • dist/ Product files of sugar.js and mvvm.js, and their compressed.

  • src/ Source code module files:

    • src/main/20% A simple component system. API & Doc

    • src/mvvm/80% A powerful and easy-using MVVM library. API & Doc

  • test/ Unit test specs writing by karma + jasmine.

Contribution

  1. Fork and clone repository to your local

  2. Install nodejs package devtools: npm install

  3. Develop and debug: npm run dev (generate sourcemap files in bundle/)

  4. Add and write test spec, (in test/units/specs/) then run uint test:npm run test

  5. Generate the test coverage report and jshint checking up: npm run build

ChangeLog

See releases

License

MIT License

About

A lightweight JavaScript MVVM library for building web UI component.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 93.6%
  • CSS 3.3%
  • HTML 2.5%
  • Other 0.6%