All Projects → leshniak → necktie

leshniak / necktie

Licence: MIT license
Necktie – a simple DOM binding tool

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to necktie

rottenjs
An all-in-one (2.6kb) Javascript library for web development
Stars: ✭ 15 (-65.12%)
Mutual labels:  dom, javascript-library, dom-manipulation
m4q
Small library for DOM manipulation and animation. This library similar to jQuery, but written more simply.
Stars: ✭ 30 (-30.23%)
Mutual labels:  dom, dom-manipulation
bound
Data-binding made easy
Stars: ✭ 21 (-51.16%)
Mutual labels:  binding, typescript-library
picoCSS
picoCSS - really small JavaScript Framework
Stars: ✭ 62 (+44.19%)
Mutual labels:  dom, javascript-library
rxjs-ninja
RxJS Operators for handling Observable strings, numbers, booleans and more
Stars: ✭ 68 (+58.14%)
Mutual labels:  javascript-library, typescript-library
validate-polish
Utility library for validation of PESEL, NIP, REGON, identity card etc. Aimed mostly at Polish enviroment. [Polish] Walidacja numerów pesel, nip, regon, dowodu osobistego.
Stars: ✭ 31 (-27.91%)
Mutual labels:  javascript-library, typescript-library
Mei.js
a minimal, simple and helpful library for you
Stars: ✭ 15 (-65.12%)
Mutual labels:  dom, javascript-library
sqlweb
SqlWeb is an extension of JsStore which allows to use sql query for performing database operation in IndexedDB.
Stars: ✭ 38 (-11.63%)
Mutual labels:  javascript-library, typescript-library
Dom
Modern DOM API.
Stars: ✭ 88 (+104.65%)
Mutual labels:  dom, dom-manipulation
domonic
Create HTML with python 3 using a standard DOM API. Includes a python port of JavaScript for interoperability and tons of other cool features. A fast prototyping library.
Stars: ✭ 86 (+100%)
Mutual labels:  dom, dom-manipulation
Html Dom
This project is developed by Nguyen Huu Phuoc. I love building products and sharing knowledge.
Stars: ✭ 4,269 (+9827.91%)
Mutual labels:  dom, dom-manipulation
nojs
Library that helps minimize js you have to write
Stars: ✭ 118 (+174.42%)
Mutual labels:  javascript-library, dom-manipulation
safe-touch
⛓ Runtime optional chaining for JS
Stars: ✭ 71 (+65.12%)
Mutual labels:  javascript-library, typescript-library
Gojs
JavaScript diagramming library for interactive flowcharts, org charts, design tools, planning tools, visual languages.
Stars: ✭ 5,739 (+13246.51%)
Mutual labels:  javascript-library, typescript-library
react-picture-annotation
A simple annotation component.
Stars: ✭ 53 (+23.26%)
Mutual labels:  javascript-library, typescript-library
PopUpOFF
Chrome extension, providing better web experience.
Stars: ✭ 65 (+51.16%)
Mutual labels:  dom, mutationobserver
constant-time-js
Constant-time JavaScript functions
Stars: ✭ 43 (+0%)
Mutual labels:  javascript-library, typescript-library
Glize
📚 Glize is a clean and robust pure Javascript library.
Stars: ✭ 16 (-62.79%)
Mutual labels:  javascript-library, dom-manipulation
Dom7
Minimalistic JavaScript library for DOM manipulation, with a jQuery-compatible API
Stars: ✭ 119 (+176.74%)
Mutual labels:  dom, javascript-library
Waff Query
Lightweight DOM manager
Stars: ✭ 9 (-79.07%)
Mutual labels:  dom, javascript-library

👔 Necktie – a simple DOM binding tool

Necktie is a library that binds your logic to the Document Object Model elements in an easy way. It has only ~3kB (UMD, minified).

version downloads jsDelivr hits MIT License

How it works

Necktie takes its powers from document.querySelector and MutationObserver capabilities. This tool allows you to register a function or a class that will be called with a proper Element as an argument, even if it's created or removed dynamically.

For example:

import { Necktie } from '@lesniewski.pro/necktie';

const tie = new Necktie();

tie.startListening();

tie.bind('.form-component input[data-name]', (element) => {
  console.log(element, 'has been found in the DOM');

  return (removedElement) => {
    console.log(removedElement, 'has been removed from the DOM');
  };
});

Necktie is meant for mostly static pages, but should work also in SPA model, although it may be CPU-expensive, especially using observeAttributes().

Give it a try!

Installation

Using:

Documentation

It's recommended to include Necktie in the <head> section of the document.

The library comes with CJS, ESM and UMD modules. TypeScript types are also available.

Components

Necktie class

Method Description
constructor(parent?: ParentNode): this Creates a new Necktie instance. Optionally provide a custom parent node (defaults to the root document node).
bind(selector: string, callback: Callback): this Binds a callback function with a given selector.
bindClass(selector: string, BindableComponent: Bindable): this Binds a Bindable class with a given selector.
observeAttributes(isEnabled?: boolean): this Looks for attributes changes, for example class or data-*. Rebinds registered functions if necessary. WARNING! Use with caution, this may be expensive.
startListening(): this Runs callbacks or Bindable classes on registered selectors, starts listening for DOM changes.
stopListening(): this Stops observing DOM changes.

Bindable class

Method Description
constructor(element?: Element): this Creates a new Bindable instance.
destroy(removedElement?: Element): void A clean up method, called when a DOM element has been removed.

Callback function

(element?: Element) => ((removedElement?: Element) => void) | void – a function fired when a proper Element has been found. Optionally it can return a clean up function that will be fired when the element will disappear from the DOM.

TO DO

  • Initial release
  • Unit tests
  • CI automation

Sponsorship

If you appreciate my work, it will be cool to know that I drink my coffee thanks to you!

License

MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].