Giter Club home page Giter Club logo

simple-dom-bindings's Introduction

Simple Dom Bindings

This experimental library enables you to establish multiple two way smart bindings with DOM Nodes.The idea is to create a JS virtual dom library that creates smart bindings with js objects in a script or application just like how in React your JSX automatically flushes all the changes to vDOM and then from there only the new changes are commited to the actual DOM. It would be amazing if instead of JSX we could connect vDOM directly with objects that contain your state even in non-react applications.

Getting Started

Usage

import { bindToDOM } from 'simple-dom-bindings'

const App = bindToDOM([
  {
    accessor: 'version',
    query: '#version',
    initialValue: '1.0.0',
  },
  {
    accessor: 'firstName',
    query: '.firstName',
    initialValue: 'John',
  },
  {
    accessor: 'firstNameClass',
    attribute: 'class', // can bind to dom attributes
    query: '.firstName',
    initialValue: 'primary-text',
  },
  {
    accessor: 'lastName',
    query: 'input#lastName', // handle text inputs
    initialValue: 'Doe',
  }
])

// at this point your App object has established a two way
// binding with the corresponding DOM nodes

console.log(App)
// { version: '1.0.0', firstName: 'John', firstNameClass: 'primary-text' , lastName: 'Doe' }

// will update the corresponding DOM node value to `Peter`
App.firstName = 'Peter'

// will not update the corresponding DOM node value to `Peter`
// as it is already the same value
App.firstName = 'Peter'

// will update the corresponding DOM node value to `Elon`
App.firstName = 'Elon'

I use this mostly in vanilla JS,HTML,CSS projects without a framework.

Contributing

Before you submit a pull request, please take the following actions.

  1. Open an issue describing the contribution you would like to make
  2. Discuss until we all agree that your idea is useful for the project
  3. Create a pull request but make sure you follow the style guide and the tests pass
  4. Voila! You've done an amazing job.

License

MIT @ Tushar Sharma

simple-dom-bindings's People

Contributors

tusharf5 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.