Git Product home page Git Product logo

xstate-behaviors's Introduction

xstate-behaviors

Making web workers, web sockets, WebRTC, and other web-based APIs first-class actors in xstate.

This package is not yet release as it is in a very early alpha state. If you would like to use any of these helpers now its recommended to copy and paste them into your codebase for the time being!

If you have any ideas for other Web APIs to support please file an issue!

Helper functions

Any of the helper functions exported from this library can be used to invoke or spawn an actor that wraps around a certain Web API.

Async

  • fromDynamicImport
    • Invoke/spawn a machine that is dynamically imported. Events sent to the machine while the dynamic import are loading are deferred until the machine is started.

Workers

It is assumed that events sent to/from the worker are of the type EventObject, otherwise they are ignored.

  • fromWebWorker
    • Invoke/spawn a web worker.
    • interpretInWebWorker
      • Interpret a machine inside a web worker whose parent is on the main thread. This means that you can use sendParent in your machine to send events out of the web worker.
  • fromSharedWorker
    • Invoke/spawn a shared worker.
    • interpretInSharedWorker
      • Interpret a machine inside a shared worker whose parent is on a main thread. This means that you can use sendParent in your machine to send events out of the web worker.
  • fromServiceWorker
    • Invoke/spawn an actor that lets you communicate with a service worker. It is assumed that events sent from the worker are of the type EventObject.
  • fromAudioWorklet
    • Invoke/spawn a AudioWorklet.

Real-time

It is assumed that events sent over the network are of the type EventObject, otherwise they are ignored.

  • fromWebSocket
    • Invoke/spawn a web socket.
  • fromEventSource
    • Invoke/spawn a event source for server side events.
  • fromWebRTC (TODO)
    • Still figuring this out let me know if you have any idea!

Events

  • fromEventBus
    • Invoke/spawn an event bus so non-hierarchical actors can communicate
    • EventBus is a class that encapsulates an event bus. This is not a web API.
  • fromBroadCastChannel
  • Invoke/spawn a BroadcastChannel to communicate with anyone else listening
  • fromEventListener
    • Invoke/spawn an event from
  • fromPostMessage (TODO)
  • fromMessageChannel (TODO)

TODO

  • Finish building out planned helpers.
  • Add ability to filter out unwanted events.
  • Add more tests/examples.
  • Build out documentation.

xstate-behaviors's People

Contributors

chrisshank avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

xstate-behaviors's Issues

data fetching with indexDb

What would be the best way to structure a machine focused solely on data-fetching / storage with IndexDb?

I have an api machine, which is responsible for communicating with the serve api. It has a variety of gql (or rest) queries that it can make, in response to a request event. It checks indexdb to see if it already has the data. If not, it fetches it and stores it, and then responds with the data.

The hope is that all this would take place in a web worker, so if I need to fetch some massive data-sets, its not using the main thread.

Helpers for WebRTC

Im new to WebRTC and still exploring what helpers would be helpful for apps to integrating WebRTC easier. Any ideas/guidance?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.