Skip to content

Releases: matthewp/haunted

v6.0.0-next.1

18 May 18:49
122bd4a
Compare
Choose a tag to compare
v6.0.0-next.1 Pre-release
Pre-release

Patch Changes

  • 9c9bd24: Prevent a setState that doesn't change the state from resulting in a rerender

v6.0.0-next.0

18 May 15:55
f6fcc6e
Compare
Choose a tag to compare
v6.0.0-next.0 Pre-release
Pre-release

Major Changes

  • f861a4b: Deprecates haunted.js and web.js bundles

v5.0.0

18 May 16:40
Compare
Choose a tag to compare

4.7.0

16 Dec 11:31
Compare
Choose a tag to compare

Adds the initializer argument to useReducer, #160.

4.6.3

24 Nov 21:50
Compare
Choose a tag to compare

Fail gracefully when useMemo is called without deps. #153

4.6.1

27 Sep 12:05
Compare
Choose a tag to compare

Fixes a bug that prevented the use of the title attribute.

4.6.0

21 Sep 12:11
Compare
Choose a tag to compare

This is a huge release for Haunted, one of the biggest since the initial release. Before getting into features I want to give some appreciate to @jdin, @Gladear, and @chase-moskal who all made tremendous contributions to this release. That cannot go overstated, I did only a small part of this release, the Haunted community is what keeps this project alive. 鉂わ笍 馃巸 . Now that the sappy stuff is complete, on to the features!

State API

At its core Haunted is a container for state and lifecycle callbacks that is derived from hooks like useState, useMemo, even useEffect. With the component() API you get more than just that, you also get a scheduler that handles rendering and committing the result.

A lot of people have wanted to use hooks outside of the context of Haunted components. One example is using hooks inside of a LitElement component. The new State API enables this, by exposing the low-level part of Haunted which is its state container.

Here's an example of how State can be used to mixin with other base element classes:

import { LitElement } from 'lit-element';
import { State } from 'haunted';

export default class LitHauntedElement extends LitElement {
  constructor() {
    super();

    this.hauntedState = new State(() => this.requestUpdate(), this);
  }

  update(changedProperties) {
    this.hauntedState.run(() => super.update(changedProperties));
    this.hauntedState.runEffects();
  }
}

When you would then use like:

import LitHauntedElement from './lit-haunted-element.js';
import { useState } from 'haunted';
import { html } from 'lit-element';

class MyApp extends LitHauntedElement {
  render() {
    const [count, setCount] = useState(0);

    return html`
      <div>Count: ${count}</div>
      <button @click=${() => setCount(count + 1)}>
        Increment
      </button>
    `;
  }
}

See this gist for other example integrations.

@jdin has built a new LitElement integration which can be installed, haunted-lit-element. 馃帀

useLayoutEffect

This is one of the more obscure hooks, but useLayoutEffect is useful when you want to do something right after the DOM is rendered. An example would be setting up adoptedStyleSheets like so:

import { useLayoutEffect, component } from 'haunted';
import { css, html } from 'lit-element';

function useAdoptedStylesSheets(el, ...sheets) {
  useLayoutEffect(() => {
    el.adoptedStyleSheets = [
      ...el.adoptedStyleSheets,
      ...sheets
    ];
  });
}

const styles = css`
  h1 { color: blur; }
`;

function MyApp() {
  useAdoptedStyleSheets(this, styles);
  
  return html`
    <h1>Hello world!</h1>
  `;
}

customElements.define('my-app', component(MyApp));

TypeScript

Haunted is now written in TypeScript, so all of the problems that TypeScript users have had in the past with imperfect type definitions should not be a problem going forward. Huge thanks to @Gladear who implemented the conversion (as well as useLayoutEffect)! 馃帀

4.5.4

01 Sep 15:09
Compare
Choose a tag to compare

Minor fixes in typings from #131

4.5.3

26 Aug 13:29
Compare
Choose a tag to compare

This is a patch release, which fixes #127 and ensures that Haunted components are instancesof HTMLElement.

4.6.0-beta.0 - The new State API

19 Aug 12:49
Compare
Choose a tag to compare

馃 馃巸 This is an initial beta release of the new State API. The State API is a low-level way to create instances of hooks state. It provides methods for running hooks code and a callback for when any hook state has changed. The intended use-case is integration with base classes such as SkateJS and LitElement.

Since the API is lower-level, we feel it should be first released as a beta so developers interested in creating integrations with base classes can try it out and see if there are any holes to be filled. When those developers as satisfied it will come in a future minor release, likely 4.6.0.

Here's a small example of how the State API works at its lowest level:

import { State, useState } from 'haunted';

let state = new State(() => {
  update();
});

function update() {
  state.run(() => {
    const [count, setCount] = useState(0);

    console.log('count is', count);

    setTimeout(() => setCount(count + 1), 3000);
  });
}

update();

More example integrations can be found in this gist. Also see the documentation in the readme here.