• Stars
    star
    572
  • Rank 77,995 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Smart and efficient javascript object observer, ideal for batching DOM updates (~1kb)

icaro

A smart and efficient javascript object observer, ideal for batching DOM updates (~1kb)

Build Status NPM version NPM downloads MIT License

Installation

Via npm

$ npm i icaro -S

Script import

Via <script>

<script src='path/to/icaro.js'></script>

Via ES2015 modules

import icaro from 'icaro'

Via commonjs

const icaro = require('icaro')

Demos

Performance

icaro is really fast compared to the other reactive libs because it smartly throttles all the state changes.

Usage

icaro will let you listen to all the changes happening in a javascript object or array, grouping them efficiently, and optimizing the performance of your listeners.

const obj = icaro({})

// the variable "changes" here is a Map and the function is async
obj.listen(function(changes) {
  console.log(changes.get('foo')) // 'hi'
  console.log(changes.get('bar')) // 'there'
  console.log(changes.get('baz')) // 'dude'

  // kill all the listeners
  obj.unlisten()
})

obj.foo = 'hi'
obj.bar = 'there'
obj.baz = 'dude'

icaro will also let you listen to nested objects and all the non primitive properties added to an icaro object will be automatically converted into icaro observable objects.

const obj = icaro({})

// listen only the changes happening on the root object
obj.listen(function(changes) {
})

obj.nested = {

}

obj.nested.listen(function(changes) {
  // listen only the changes of obj.nested
})

obj.nested.someVal = 'hello'

icaro is able also to listen changes in arrays. Any change to the items indexes will dispatch events.

// Here a bit of hardcore async stuff

const arr = icaro([])

// here you will get the index of the items added or who changed their position
arr.listen(function(changes) {
  console.log(changes.get('0')) // 'foo'
  console.log(changes.get('1')) // 'bar'
  // kill all the listeners this included
  arr.unlisten()

  // add a brand new listener recursively.. why not?
  arr.listen(function(changes) {
    // the change was triggered by a 'reverse' and all indexes were updated
    console.log(changes.get('0')) // 'bar'
    console.log(changes.get('1')) // 'foo'
  })

  // update all the indexes
  arr.reverse()
})

// initial dispatch
arr.push('foo')
arr.push('bar')

You can also avoid unsubscribing ("unlisten") because icaro will automatically remove event listeners when the object is about to be garbage collected.

API

Any icaro call will return a Proxy with the following api methods

icaro.listen(callback)

Listen any object or array calling the callback function asynchronously grouping all the contiguous changes via setImmediate

@returns self

icaro.unlisten(callback|null)

Unsubscribing a callback previously subscribed to the object, if no callback is provided all the previous subscriptions will be cleared

@returns self

icaro.toJSON()

Return all data contained in an icaro Proxy as JSON object

@returns Object

Support

icaro uses advanced es6 features like Proxies, WeakMaps, Maps and Symbols and it targets only modern browsers

All major evergreen browsers (Edge, Chrome, Safari, Firefox) should be supported

More Repositories

1

allora

Promisify using es6 Proxies every javascript API with less than 50 lines of code
JavaScript
679
star
2

Tocca.js

Super lightweight script (~1kb) to detect via Javascript events like 'tap' 'dbltap' 'swipeup' 'swipedown' 'swipeleft' 'swiperight' on any kind of device.
JavaScript
659
star
3

Vague.js

Vague.js is an experimental script that allows you to blur any kind of html element thanks to the SVG filters
JavaScript
604
star
4

es6-project-starter-kit

Universal Starter Kit to build any javascript ES6 project/library runnable in nodejs and on any browser.
JavaScript
460
star
5

jQuery.BlackAndWhite

Clientside grayscale images on any browser
JavaScript
311
star
6

jquery.html5loader

jQuery.html5Loader can preload images, SVGs, html5 video and audio sources, scripts, css, and text files.
JavaScript
302
star
7

parallax

ES6/ES2015 HW accelerated scrollable images parallax
JavaScript
276
star
8

go-observable

It allows you to send and receive events with a tiny simple API
Go
240
star
9

nodejs-MySQL-push-notifications-demo

Node server that is able to read from a MySql database and then stream those data via websocket to many client connected on the same page
JavaScript
106
star
10

nodejs-push-notification-server

Simple nodejs push notification server using socket.io
JavaScript
76
star
11

riot-app-example

Simple riotjs isomorphic app
JavaScript
76
star
12

animore

1kb script that will make your DOM state transitions smoother & easier
JavaScript
72
star
13

erre

Modern, performant and tiny (~0.5kb) streams script using generators for browsers and node.js
JavaScript
30
star
14

nodejs-arduino-example

Simple example to show how to use arduino to communicate digital signals to a nodejs server
JavaScript
25
star
15

cmt

Get rid of all the boring git commit messages like 'small fix'. cmt is an automatic git commit generator
JavaScript
18
star
16

site-under-construction

Simple splash page to use while a site is still under construction
CSS
17
star
17

fcf

Monadic Functional Control Flow Micro-Library for Javascript/Typescript
TypeScript
14
star
18

rawth

Pure functional isomorphic router based on streams
JavaScript
14
star
19

fortytwo

List of interactive prompt helpers to pimp the UIs of your haskell programs
Haskell
12
star
20

reactive-libs-bench

Benchmark tests to check some popular reactive libraries - raw tests no DOM involved
JavaScript
11
star
21

days-since-last-javascript-drama

Timer to track how many days passed since the latest Javascript drama
HTML
9
star
22

riot-preset-babel-test

JavaScript
8
star
23

threejs-amd-bootstrap

Simple and lite threejs bootstrap project build using requirejs
JavaScript
7
star
24

nisiu

Password manager written in Riot.js
HTML
6
star
25

i-got-ya

Stop fucking with my machine when I am not here :)
Go
6
star
26

the-cost-of-native-javascript-modules

The performance cost of native javascript modules
HTML
5
star
27

immutable-dom

Lock any HTML DOM Element 🔐
JavaScript
4
star
28

ruit

Functional tasks serialization mini script (0.3kb)
JavaScript
4
star
29

jquery-fitToParent

A jQuery plugin for proportionally scaling an element to its parent element. Useful for thumbnails and avatars.
JavaScript
4
star
30

package-requirejs

Generate a valid requirejs-config.js file automatically detecting all the package.json dependencies
JavaScript
4
star
31

riot-now-demo

Simple now riot component
3
star
32

Caronte.js

Simple javascript ajax file uploader script made for the modern browsers
JavaScript
3
star
33

EasyAnimationFrame

Using EasyAnimationFrame.js you can make html5 canvas or html animations having the complete control over the framerate.
JavaScript
3
star
34

riot-chrome-extension

riojs chrome extension example
JavaScript
3
star
35

rob

Personal projects generator written in haskell
Haskell
3
star
36

smell-of-funtional-programming

Demo code for the "Smell Of Functional Programming" presenation
JavaScript
3
star
37

SublimeText2-Parallel-Builder-Plugin

Sublime Text2 Plugin - It allows you to run more than one build command in Parallel
Python
3
star
38

gianlucaguarini.github.io

gianlucaguarini.github.io original source
HTML
3
star
39

cumpa

Minimal function composition implementation
JavaScript
2
star
40

riot-ssr-now

Simple riot example to demonstrate how to deploy on zeit.co
JavaScript
2
star
41

curri

Minimal curry implementation
JavaScript
2
star
42

mail-client-ui-demo

Simple Mail Client Demo with ~20 Javascript code
JavaScript
2
star
43

grunt-testardo

grunt plugin to test your project using testardo
JavaScript
2
star
44

html5-semantic

Meaningful HTML5 Designs - webzurich - 25.05.2020
2
star
45

the-colour-of-the-moment

Random colored image generator service written with go
Riot
2
star
46

executor

Haskell module to execute single or multiple shell commands
Haskell
1
star
47

amp-vs-pwa-vs-HTML

Simple Benchmark to check the speed of 3 different website types
HTML
1
star
48

the-fly

JavaScript
1
star
49

OSXKeyboard

Go helper script to detect the global keypress events on OSX
C
1
star