npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hacktiv

v0.0.4

Published

Auto re-execute functions when data change

Downloads

11

Readme

Hacktiv

NPM

Implementation of the Functional reactive programming (FRP) paradigm, using reactive values. (Naive implementation of Meteor Tracker)

Used to keep track of variable values, and automaticaly execute code when a value change.

It automaticaly guess data dependencies, and when one of them change, every Hacktiv functions that depends on this data are retriggered to take consideration of the new values.

Install

$> npm install hacktiv

Quick Start

Will successively print 'test' and 'test2':

Hacktiv = require 'hacktiv'

# Get a new reactive value
value = new Hacktiv.Value 'test'

# The Hacktiv function will keep track of reactive values,
# re-executing the function if any of the values or any
# of their dependencies called inside have changed
Hacktiv ->

  # Calling the value without parameter returns the actual value
  console.log value()

# [...]

# Calling the value with a parameter update the underlying value and will reprint
value 'test2'

Will successively print 'One Two' and 'One Three' :

value = new Hacktiv.Value 'One'

value2 = new Hacktiv.Value 'Two'

# Here if any of value or value2 change,
# the console.log will reprint these two values
Hacktiv ->
  console.log value() + ' ' + value2()

value2 'Three'

Will successively print 'test' and 'test2' :

value2 = new Hacktiv.Value 'test'

# You can set reactive values as Functions or Objects.
# They can reference other values, that will cause the Hacktiv function
# to rerun if any of them change
value = new Hacktiv.Value ->
  value2()

Hacktiv ->
  console.log value()

value2 'test2'

Status

You can check if you are in a watching context with Hacktiv.active booleen

console.log Hacktiv.active    #false

Hacktiv ->
  console.log Hacktiv.active  #true

console.log Hacktiv.active    #false

Stop watching

To stop watching, just get the handler back from your Hacktiv function and call its Stop() function

value = new Hacktiv.Value 1

handler = Hacktiv ->
  console.log value()

value2 'test2'

handler.Stop()

# This call will not refresh the function
value2 'test3'

You can temporarily stop watching with Hacktiv.DontWatch() :

Hacktiv ->

  Hacktiv.DontWatch ->
    # Here values are not monitored

Playing with the Dependency object

Will successively print [], ['test1'] and ['test1', 'test2'] :

Hacktiv = require 'hacktiv'

class List extends Hacktiv.Dependency

  tasks: []

  AddTask: (task) ->
    @tasks.push task
    @_Changed()

  Send: ->
    @_Depends()
    @tasks

list = new List

Hacktiv ->

  # Replace this with a websocket or a stream
  console.log list.Send()

list.AddTask 'test1'
list.AddTask 'test2'

Limits

When multiples Hacktiv functions run simultaneously, dependencies may not be correctly guessed cause of the global bus event 'depends', catched by every Computations

API

Hacktiv

The Hacktiv is the main function, taking track of every computations.

  • Hacktiv(function)
    • Add a new Computation with the given function

Computation

  • constructor(function)

    • Start recording, Run the function, Stop recording.
  • StartRecord()

    • Keep track of every Dependencies that run their _Depends() call
  • StopRecord()

    • Stop recording for Dependencies

Dependency

  • constructor()

    • Set the unique id for the dependency
  • _Depends()

    • Send a global event to tell current recording Computation that a value has been accessed.
  • _Changed()

    • Send a localised event to each Computations that have catched the Dependency that a value has changed.

Value

Is a function that take one argument.

  • With argument: Setter
  • Without argument: Getter

TODO

  • Jail the Computation Record methods to avoir Dependencies collisions
  • Provide methods to stop watching

Changelog

  • Simplified syntax for Value. Now useable directly as function taking no parameter for Get and taking one for Set