GithubHelp home page GithubHelp logo

glocq / purescript-halogen-subscriptions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from purescript-halogen/purescript-halogen-subscriptions

0.0 0.0 0.0 23 KB

Utilities for creating and transforming push-based subscriptions.

License: Apache License 2.0

PureScript 91.21% Dhall 8.79%

purescript-halogen-subscriptions's Introduction

Halogen Subscriptions

CI Release Pursuit Maintainer: garyb Maintainer: thomashoneyman

Utilities for creating and managing push-based subscriptions, inspired by the event library. This library is used to implement subscriptions in Halogen, but it can be used independently of Halogen.

Installation

Install halogen-subscriptions with Spago:

spago install halogen-subscriptions

Quick start

The halogen-subscriptions library helps you create and transform push-based subscriptions. Most subscriptions follow this pattern:

  1. Use the create function to produce a paired Emitter and Listener. An emitter is a possibly-infinite list of values that you can subscribe to, and a listener is a mechanism for pushing values to the emitter.
  2. Use the subscribe function to subscribe to outputs from the emitter by providing a callback function to run each time a value is emitted.
  3. Use the notify function to push values to the emitter via the listener.
  4. Use the unsubscribe function to end a subscription to an emitter.

Here's a simple example that logs "Hello" and then "Goodbye":

module Main where

import Prelude

import Effect (Effect)
import Effect.Console as Console
import Halogen.Subscription as HS

main :: Effect Unit
main = do
  { emitter, listener } <- HS.create

  subscription <- HS.subscribe emitter \str -> Console.log str

  HS.notify listener "Hello"
  HS.notify listener "Goodbye!"

  HS.unsubscribe subscription

Emitters can be combined and transformed to make more sophisticated subscriptions.

Documentation

Module documentation is published on Pursuit.

purescript-halogen-subscriptions's People

Contributors

thomashoneyman avatar

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.