# can-hot

> Hot reloading for canjs components

Latest version **0.1.8** (published 2017-06-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install can-hot
pnpm add can-hot
yarn add can-hot
bun add can-hot
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.8 |
| Published | 2017-06-02 |
| First published | 2016-01-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | whitecolor |
| Maintainers | whitecolor |
| Keywords | can, canjs, hot, reload, hrm |

## Links

- npm: https://www.npmjs.com/package/can-hot
- Repository: https://github.com/whitecolor/can-hot
- Homepage: https://github.com/whitecolor/can-hot#readme
- Issues: https://github.com/whitecolor/can-hot/issues
- npm.io page: https://npm.io/package/can-hot

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 0.1.8 (latest) — 2017-06-02
- 0.1.7 — 2016-03-10
- 0.1.6 — 2016-02-06
- 0.1.5 — 2016-02-06
- 0.1.4 — 2016-02-03
- 0.1.3 — 2016-02-02
- 0.1.2 — 2016-02-01
- 0.1.1 — 2016-01-31
- 0.1.0 — 2016-01-31

## README

# Can-Hot

**REAL** and frictionless *hot reloading for [CanJS](https://github.com/canjs/canjs)* components without loosing state!

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)

##What is it

[CanJS](https://github.com/canjs/canjs) is a great framework (library) for building dynamic web applications. 
It gives out of the box everything you need to build modern dynamic web UIs, while keeping it simple.

**Can-Hot** is a small add-on aimed to make your DX (developers experience) much more pleasant and with less friction,
it allows you to **tweak can.Components in realtime** the same way as for example [React Hot Loader](http://gaearon.github.io/react-hot-loader/)
for React does, so you need rarely bother about full page reloads while application development process.

![can-hot](https://cloud.githubusercontent.com/assets/736697/12709893/5b1727e8-c8d2-11e5-8f69-faf73ede4559.gif)

##Install

```bash
npm install can-hot
```
**NB!** Implicitly depends on `can@2.3.x` and `jquery` npm modules.

##Usage

**Can-hot** provides a basic mechanics for **hot-swapping can.Components** and can be used with any set of tools 
for hot-reloading. Given example uses [Steal-HMR](https://github.com/whitecolor/steal-hmr) 
and [Watchalive Dev Server](https://github.com/whitecolor/watchalive). 

```html
<script src="/node_modules/steal/steal.js">    
  import HMR from 'steal-hmr'
  import canHot from 'can-hot'
   
  // We can call `canHot.reload()` method any time when 
  // some `can.Component` has been replaced by new instance
  // but we need to know when it actually happens, 
  // so are using it here with Steal-HMR.    

  // We may instruct Can-Hot to preserve state of reloaded components.
  // Components having their own state is not very good thing
  // and side effects are possible, so it is `false` by default
  canHot.config({preserveState: true})

  new HMR({                    
    main: 'app',                
    // Here we just attach Can-Hot's `after` hook to Steal-HMR,
    // so Can-Hot knows when reloading are finished.
    plugin: [canHot],       
    handle: watchalive.onFiles,   
    teardown: () => $('bmi-app').remove()
  })
</script> 
```

##API
Your can configure using `canHot.config` following options:   
- **preserveState** (`false`) - keep state of reloaded components (attribute values on `viewModel`
will be restored) 
- **insertedEvent** (`true`) - execute `inserted` event method
- **removedEvent** (`true`) - execute `removed` event method
- **hotEvents** (`true`) - execute `beforeHot` and `afterHot` component's events method

##Try and explore sources of demo app

Try and test how all this works with module's demo app.
```bash
git clone http://github.com/whitecolor/can-hot
npm install # please, use NPM 3, otherwice remove system.npmAlgorithm in package.json
npm run start # app will run on 7000, to use other port: npm run start -- --port your_port
```
Open your browser http://localhost:7000
You can changes files `js/css/less` *inside the app folder* and see what happens
Notice that css/less reload do not made any changes to apps current state

*NB!* This demo app uses watchalive server-side pre-compilation for *.js sources with 
[BabelJS](https://babeljs.io) for the sake of example.

##Licence

ISC.

---
_Source: https://npm.io/package/can-hot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
