Content-Length: 275841 | pFad | http://github.com/SanderRonde/wc-lib/tree/master/examples/tic-tac-toe-manual

B6 wc-lib/examples/tic-tac-toe-manual at master · SanderRonde/wc-lib · GitHub
Skip to content

Latest commit

 

History

History

tic-tac-toe-manual

Tic Tac Toe (manual updates)

This example serves as a demo of manual updating using watching of values

How it works

Manually updated values use the idea of only updating a value where it's used and not doing a complete re-render of the page. To do this, we use lit-html's directives, which allow the setting of parts' (basically a representation of any used template value) values at any time. For example the following directive:

const waitFor = directive(
    (promise: Promise<any>, placeholder: string) => (part) => {
        part.setValue(placeholder);
        part.commit();

        promise.then((value) => {
            part.setValue(value);
            part.commit();
        });
    }
);

function someAsyncFetch() {
    return new Promise((resolve) => {
        setTimeout(() => resolve('value'), 5000);
    });
}

const template = html`<div>${waitFor(someAsyncFetch(), 'placeholder')}</div>`;

// Results in
// <div>placeholder</div>
// ... and after 5 seconds
// <div>123</div>

Allows you to wait for someAsyncFetch's value and have placeholder as the placeholder. We can use this to update the part whenever the underlying value changes, which is great since that is the whole idea behind props and i18n. Unfortunately we can't apply the same logic to themes because lit html does not support parts within CSS style tags.









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/SanderRonde/wc-lib/tree/master/examples/tic-tac-toe-manual

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy