Coder Social home page Coder Social logo

anshu-krishna / one-way-dom-binder Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 4 KB

One-way DOM binder using a moustache like template.

License: MIT License

HTML 32.22% JavaScript 67.78%
javascript javascript-library dom dom-binding moustache one-way-binding one-way-data-binding

one-way-dom-binder's Introduction

DOMElementBinder

One-way DOM binder

This library provides a class called DOMElementBinder which facilitates an easy way for one-way DOM binding. It allows us to specify the binding sites using a moustache like template.

Example:

Binding sites can be the textContent or the attribute value. For example

<div id="mydiv">
	Name: {{name}}; Age: {{age}};
	<div>
		Name: <b>{{name}}</b>; Age: <b>{{age}}</b>;
	</div>
	<div data-test="Name: {{name}}; Age: {{age}};"></div>
	<span data-name="{{name}}" data-age="{{age}}"></span>
</div>

Now we can link the #mydiv node to a binder object

let binder = new DOMElementBinder(document.querySelector("#mydiv"));

This binder object will now provide the variables that are binded to the specified sites.

binder.name = "Anshu";
binder.age = 25;

The above assignments will be automatically reflected in the DOM as

<div id="mydiv">
	Name: Anshu; Age: 25;
	<div>
		Name: <b>Anshu</b>; Age: <b>25</b>;
	</div>
	<div data-test="Name: Anshu; Age: 25;"></div>
	<span data-name="Anshu" data-age="25"></span>
</div>

one-way-dom-binder's People

Contributors

anshu-krishna avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.