|
1 | | -## Welcome to GitHub Pages |
2 | | - |
3 | | -You can use the [editor on GitHub](https://github.com/hertonwork/updatr/edit/main/README.md) to maintain and preview the content for your website in Markdown files. |
4 | | - |
5 | | -Whenever you commit to this repository, GitHub Pages will run [Jekyll](https://jekyllrb.com/) to rebuild the pages in your site, from the content in your Markdown files. |
6 | | - |
7 | | -### Markdown |
8 | | - |
9 | | -Markdown is a lightweight and easy-to-use syntax for styling your writing. It includes conventions for |
10 | | - |
11 | | -```markdown |
12 | | -Syntax highlighted code block |
13 | | - |
14 | | -# Header 1 |
15 | | -## Header 2 |
16 | | -### Header 3 |
17 | | - |
18 | | -- Bulleted |
19 | | -- List |
20 | | - |
21 | | -1. Numbered |
22 | | -2. List |
23 | | - |
24 | | -**Bold** and _Italic_ and `Code` text |
25 | | - |
26 | | -[Link](url) and  |
| 1 | +## Updatr Js simple Observer |
| 2 | + |
| 3 | +This is a very simple observer that can be used to bind an input value to an element anywhere on the DOM. |
| 4 | + |
| 5 | + |
| 6 | +```html |
| 7 | +// Example Usage |
| 8 | +<script type="module"> |
| 9 | + import { watcher, observe } from './src/index.js' |
| 10 | + // As an example, let's say we have an object coming from the backend and set as state |
| 11 | + observe(document.state) |
| 12 | + // Query all elements with the attribute called h. |
| 13 | + // For example <dd h="text"></dd> |
| 14 | + // The attribute value is the key of the attribute we wanna watch and show on the page |
| 15 | + document.querySelectorAll('[h]').forEach(element => { |
| 16 | + watcher.run(() => { |
| 17 | + element.textContent = document.state[element.attributes.h.value]; |
| 18 | + }) |
| 19 | + }) |
| 20 | + // Allowing model to change the data will trigger the event and update whoever is watching it |
| 21 | + // For example <input id="test" type="text" name="test" data-model="text"> |
| 22 | + document.querySelectorAll('[data-model]').forEach(element => { |
| 23 | + element.value = document.state[element.dataset.model]; |
| 24 | + element.addEventListener('input', () => { |
| 25 | + document.state[element.dataset.model] = element.value; |
| 26 | + }); |
| 27 | + }) |
| 28 | +</script> |
27 | 29 | ``` |
28 | 30 |
|
29 | | -For more details see [Basic writing and formatting syntax](https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax). |
30 | | - |
31 | | -### Jekyll Themes |
| 31 | +### Support or Contact |
32 | 32 |
|
33 | | -Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/hertonwork/updatr/settings/pages). The name of this theme is saved in the Jekyll `_config.yml` configuration file. |
| 33 | +Check out our [documentation](https://github.com/hertonwork/updatr#readme) |
34 | 34 |
|
35 | | -### Support or Contact |
| 35 | +## License |
36 | 36 |
|
37 | | -Having trouble with Pages? Check out our [documentation](https://docs.github.com/categories/github-pages-basics/) or [contact support](https://support.github.com/contact) and we’ll help you sort it out. |
| 37 | +[MPL-2.0](https://opensource.org/licenses/MPL-2.0) |
0 commit comments