1.4.0 • Published 5 years ago

@yaff/component-state v1.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

State Component

A custom component which can be linked to a Store state

<state-wrapper id="mystate"></state-wrapper>
// Store from @yaff/store
const store = new Store({
    state: {
        count: 0,
    },
});

const mystate = document.querySelector('#mystate');

// set the value of mystate
mystate.state = store.count;

// this will update the value in mystate
store.count++;

h literal template

//helper function for easy element creation4

const el = h`<div><button> Click me</button> Clicked ${
    store.count
} times </div>`;

document.body.append(el);

Nested functions

const store = new Store({
    state: {
        items: [],
    },
    actions: {
        add(item) {
            this.items = [...this.items, item];
        },
    },
});

store.add('Hello');
store.add('World');

// curently doesnot update automaticaly
const el = h`<div><ul>${store.items.map(
    (val, i) => h`<li key="${i}">${val}</li>`
)}</ul></div>`;

document.body.append(el);
1.4.0

5 years ago

1.3.7

5 years ago

1.3.6

5 years ago

1.3.5

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.2.16

5 years ago

1.2.14

5 years ago

1.2.12

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago