Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not very clear #3

Closed
VitoCrl opened this issue Sep 25, 2020 · 2 comments
Closed

Not very clear #3

VitoCrl opened this issue Sep 25, 2020 · 2 comments
Labels
good first issue Good for newcomers

Comments

@VitoCrl
Copy link

VitoCrl commented Sep 25, 2020

Honestly man, the script is very nice, but I don't really understand how I can integrate your webcomponents with for example the health data server, I have in my index.html file (heart Data server directory) where my heart rate is written every second, how I can integrate your bang function for display the ecg monitor ?

@tripolskypetr
Copy link
Owner

tripolskypetr commented Sep 25, 2020

Well, actually, quite simple. Call bang() on every incoming beat of heart. The provided callback is designed for a closure, inside which there can be an recursive interval with timeout and an ajax(fetch) request

Also, if you need an React interop, use the demo on JSFiddle

<!--script src="dist/ecg-webcomponent.js"></script-->

<div id="mount-point"></div>

<script>
  (function () {

    const {
      useRef,
      useEffect,
    } = React;

    const {
      createElement: h,
    } = React;

    const App = () => {

      const ref = useRef(null);

      useEffect(() => {
        const { current } = ref;
        current.innerHTML += '<ecg-line></ecg-line>';
        ecgLine((bang) => setInterval(() => bang(), 1000));
      }, []);

      return h("div", { ref });
    };

    ReactDOM.render(h(App), document.getElementById('mount-point'));

  })()
</script>

If you want to use this component with WebPack or other bundler, you need to place it's source in the global scope (window). This was discussed on StackOverflow here. Also you can code with React without any bundler, check the source code another tool here(english documentation will be published soon).

image

If this tool helps you, a your ⭐ will be appreciated)

@tripolskypetr tripolskypetr pinned this issue Sep 25, 2020
Repository owner locked as resolved and limited conversation to collaborators Sep 25, 2020
@tripolskypetr tripolskypetr added the good first issue Good for newcomers label Sep 25, 2020
@tripolskypetr
Copy link
Owner

tripolskypetr commented Sep 25, 2020

ecgLine((bang) => {
  const handler = async () => {
    const data = await fetch('http://127.0.0.1/heart/wasBeat');
    const json = await data.json();
    if (json.wasBeat) {
      bang()
    }
    setTimeout(handler, 100);
  };
  handler();
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants