@b9g/crank
Advanced tools
Changelog
[0.6.0] - 2024-04-26
ref
prop behavior has been changed. For host elements, the callback is fired once when the element is created. For component elements, the callback must be manually passed to one of the component’s children to fire. The ref
callback will have no effect for other elements like <Fragment>
.static
prop has been renamed to copy
to avoid collisions with the static
keyword.context.value
property, which allows you to access the current rendered value of a component from the context, has been deprecated.onChange
, onInput
) are now supported.for await...of
in async generator components.Changelog
[0.5.7] - 2023-12-05
Changelog
[0.5.6] - 2023-11-07
foreignObject
children having the wrong xmlns
(https://github.com/bikeshaving/crank/pull/268 by (@canadaduane)Changelog
[0.5.5] - 2023-11-06
Changelog
[0.5.4] - 2023-05-22
type="text"
does not appear in the DOM, causing surprising CSS styling issues (https://github.com/bikeshaving/crank/pull/258 by @waynebaylor)Changelog
[0.5.3] - 2023-03-12
Changelog
[0.5.2] - 2023-02-03
Context<typeof Component>
context types to be passed components with
0 parameters.Changelog
[0.5.1] - 2023-02-02
Changelog
[0.5.0] - 2023-02-01
RendererImpl
method escape()
has been renamed to text()
.RendererImpl
method parse()
has been renamed to raw()
, and
the value prop
is always passed into this method, regardless of whether the
value is a string.crank-key
, have an additional $
-prefixed variant.
Going forward, this will be the preferred syntax, but crank-key
and c-key
will continue to be supported as well.
<div $key={key} $ref={ref} $static />
for...of
or for await...of
loop will
now attempt to exit normally, so that cleanup code can be placed after the
loop.
// before
function Counter() {
let i = 0;
const interval = setInterval(() => {
i++;
this.refresh();
}, 1000);
try {
for ({} of this) {
yield <div>{i}</div>;
}
} finally {
clearInterval(interval);
}
}
// after
function Counter() {
let i = 0;
const interval = setInterval(() => {
i++;
this.refresh();
}, 1000);
for ({} of this) {
yield <div>{i}</div>;
}
clearInterval(interval);
}
async function Counter() {
let i = 0;
const interval = setInterval(() => {
i++;
this.refresh();
}, 1000);
for ({} of this) {
yield <div>{i}</div>;
}
clearInterval(interval);
}
Context
type can now be passed a function type as its first parameter
to strongly type the this
props iterators.
function *MyComponent(
this: Context<typeof MyComponent>,
{name}: {name: string},
) {
// name will be correctly inferred
for ({name} of this) {
yield <div>Hello name</div>;
}
}
The automatic JSX runtime transform is now supported. Here is the babel configuration.
plugins: [
babelPluginSyntaxJSX,
[
babelPluginTransformReactJSX,
{
runtime: "automatic",
importSource: "@b9g/crank",
},
],
],
Hydration: The DOM Renderer now provides a hydrate()
method which will
attempt to re-use DOM nodes already found on the page. A corresponding
hydrate()
method has been defined for custom renderers.
Crank now provides a tagged template function called jsx
which replicates
JSX syntax and allows templates to be written with vanilla JavaScript.
import {jsx} from "@b9g/crank/standalone";
import {renderer} from "@b9g/crank/standalone";
function Greeting({
name
}) {
return jsx`
<div>Hello ${name}</div>
`;
}
renderer.render(jsx`<${Greeting} name="world" />`, document.body);
Calling dispatchEvent()
on a component context will now trigger any
onevent
style props.
src
and other props which are sensitive to being re-assigned
will not be re-assigned.$static
elements which are re-rendered with different tags will now
correctly re-render.