GitXplorerGitXplorer
o

thermite

public
60 stars
1 forks
1 issues

Commits

List of commits on branch master.
Unverified
c034a47258aaeb7d2fef760df910536f0af163c1

Add coverage thresholds

oomphalos committed 8 years ago
Unverified
18949abbe57248bb7490af679a48498586a7e55a

Refactor and pass lint, coverage

oomphalos committed 8 years ago
Unverified
caa060a4e45be3a5fb2cc11738eca1fae5b41bc3

Bump version to 0.0.6

oomphalos committed 8 years ago
Unverified
16c6b565307b38b386576917ce24226bad070271

Update example to be more intuitive

oomphalos committed 8 years ago
Unverified
666fda1db522442e2302742b47467842b2b94723

Rebundle

oomphalos committed 8 years ago
Unverified
dfb101c4acc10512f62c81136b3059c9481f5fd6

Fix deletion tracking when adding functions

oomphalos committed 8 years ago

README

The README file for this repository.

Thermite

Build Status Coverage

Thermite gives you an API for programmatically live reloading code.

Its main purpose is to act like a library used by development and (experimentally) deployment tools.

Comparison with native browser live code reloading

I love native browser live code reloading and use it in normal development. Nevertheless there are advantages to doing live code reloading with a library.

  • Most runtimes currently do not support live code reloading, so on many browsers, if you want this feature, you're out of luck.
  • Browsers that do support this don't offer direct access to this feature from inside your program.

Thermite doesn't have these restrictions.

I'm not complaining about native browser reloading - I think it's great. But I think there's utility in having a library that gives you direct programmatic access to hot code swapping cross browser.

Demo

The demo is here.

Check it out!

Set Up

If you are using Node, first, npm install thermite, then var thermite = require('thermite')

If you are using the browser, use thermite.min.js. thermite is exposed as a global variable. Or just use browserify.

Basic usage

var hotSwappableCode = thermite.eval('(' + function() {
  document.addEventListener("mousemove", function(evt) {
    console.log(evt.clientX * evt.clientY)
  })
} + ')()')

hotSwappableCode.hotSwap('(' + function() {
  document.addEventListener("mousemove", function(evt) {
    console.log(evt.clientX + evt.clientY)
  })
} + ')()')

Calling hotSwap here doesn't add a second event listener to the DOM. It effectively replaces the reference to the event listener stored in the DOM with a new one.

How it works

Thermite works by rewriting code and proxying each function.

Additionally it stores the initial version of your code in a map.

When you call hotSwap, thermite runs a diff to identify how functions change. It uses this diff to update the map.

Whenever a function runs, it checks its version. When a function finds that its version is lower than the one in the map, it evals the new function (creating it in the proper scope).

License

MIT