Skip to content

Commit

Permalink
feat(rdom-canvas): set fallback canvas size if given as sub
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 31, 2023
1 parent 3c17520 commit 7fe9d63
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/rdom-canvas/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ export interface CanvasOpts {
*
* @remarks
* If `size` is subscribable, the canvas is resized each time a new value is
* received, else will only be used to define initial canvas size. The `attribs`
* SHOULD not include `width`, `height`, since these will be overriden in any
* way by `size` arg.
* received, else will only be used to define initial canvas size.
*
* If given a sub (for size) and it has not (yet) produced a value, a default
* canvas size of 1x1 pixel will be used.
*
* The `attribs` SHOULD not include `width`, `height`, since these will be
* overriden in any way by `size` arg.
*/
export const $canvas = (
body: ISubscription<any, any[] | IToHiccup>,
Expand Down Expand Up @@ -89,7 +93,7 @@ export class $Canvas
]);
this.el = <HTMLCanvasElement>await this.inner.mount(parent, index);
this.ctx = this.el.getContext("2d", this.attribs.ctx)!;
this.resize(this.size.deref()!);
this.resize(this.size.deref() || [1, 1]);
this.attribs.onmount && this.attribs.onmount(this.el, this.ctx);
this.update(shapes);
return this.el;
Expand Down

0 comments on commit 7fe9d63

Please sign in to comment.