Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions playground/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Cona } from "../dist/index.mjs";

// Expose Cona for debugging.
window.Cona = Cona;

Cona.style = `
* {
box-sizing: border-box;
Expand Down
10 changes: 3 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ interface State {
[key: string]: any;
}

interface Computed<T> {
get: () => T;
}

export class Cona extends HTMLElement {
private _op: Props;
private props: Props;
Expand Down Expand Up @@ -94,9 +90,9 @@ export class Cona extends HTMLElement {

for (const [valueFn, callback] of this._ef.entries()) {
const valueBeforeUpdate = this._ev.get(valueFn);
const valueAfterUpdate = valueFn.bind(this)();
const valueAfterUpdate = valueFn.call(this);
if (valueBeforeUpdate !== valueAfterUpdate) {
callback.bind(this)(valueBeforeUpdate, valueAfterUpdate);
callback.call(this, valueBeforeUpdate, valueAfterUpdate);
}

this._ev.set(valueFn, valueAfterUpdate);
Expand Down Expand Up @@ -200,7 +196,7 @@ export class Cona extends HTMLElement {
*/
effect(valueFn: EffectFunction, callback: EffectCallback) {
this._ef.set(valueFn, callback);
this._ev.set(valueFn, valueFn.bind(this)());
this._ev.set(valueFn, valueFn.call(this));
}

/**
Expand Down