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

big-brother-js

v0.4.0

Published

A javascript watcher, which evaluates an expression and fires a callback when its value changes

Downloads

7

Readme

BigBrother

A scheduler management tool for javascript.

This lightweight and programmer friendly module, written entirely in typescript, provides the means to manage multiple schedulers from one place, making it simple and stress free. BigBrother keeps track of everything so that you don't have to.

Features

  • Initialize multiple schedulers with different priorities.
  • Schedule actions with the desired priority.
  • Watch for value changes in expressions.
  • Stop and re-initialize your schedulers at will.
  • Flexible and user friendly API.

Instructions

Install


npm install big-brother-js --save

Usage

init()

To initialize the default scheduler which uses requestAnimationFrame by default (falls back to 16 ms setTimeout) simply call init() with no parameters:


BigBrother.init(); // Runs the scheduler on every frame. ( requestanimationframe() || setTimeout() )

Note: You don't need to initialize the default scheduler, unless you deliberately stop it and wish to restart it. Any call to watch() or do() without providing an interval or priorityKey will autimatically fire it.

To initialize a scheduler other than the default, you have to specify the update interval and a priorityKey.


BigBrother.init( 100, "highPriority" ); // Runs the scheduler every 100 ms.
BigBrother.init( 500, "midPriority" ); // Runs the scheduler every 500 ms.
BigBrother.init( 1000, "lowPriority" ); // Runs the scheduler every 1000 ms.

stop()

Use this method to stop the scheduler corresponding to the given priorityKey. call it with no paremeters to stop all schedulers.


BigBrother.stop( "someCustomPriority" ); // Stop only the scheduler with the given priorityKey

BigBrother.stop(); // Stop all schedulers

do()

Schedules the execution of actions with the desired priority or update interval.

To execute an action with the default scheduler simply call do() with a callback function.


BigBrother.do( ()=> "Hello Default Scheduler" ); // Will excecute the callback on every frame.

To execute an action with a specific scheduler, pass the priorityKey of the scheduler you wish to use.


BigBrother.init( 100, "customPriority" );
BigBrother.do( ()=> "Hello customPriority Scheduler", "customPriority" ); // Will execute the callback every 100 ms

BigBrother.init( 1000, "veryLowCustomPriority" );
BigBrother.do( ()=> "Hello veryLowCustomPriority Scheduler", "veryLowCustomPriority" ); // Will execute the callback every 1000 ms

Note: if the given priorityKey does not exist, it'll throw an error.

Instead of a priorityKey you could give it an update interval. If there's no scheduler with the same interval, it'll automatically create a new one. Otherwise, it'll hook to a matching scheduler.


BigBrother.init( 100, "customPriority" );

BigBrother.do( ()=> doSomething(), 100 ); // Will hook to "customPriority"
BigBrother.do( ()=> doSomething(), 255 ); // Will create a new scheduler
BigBrother.do( ()=> doSomethingElse(), 255 ); // Will hook to the scheduler created by the above action

To stop scheduling an action, call the function returned by do().


let stopSchedulingAction = BigBrother.do( ()=> doSomething() );

stopSchedulingAction();

clearScheduledActions()

Use this method to remove either all scheduled actions, or only those from the selected Scheduler.


BigBrother.clearScheduledActions( "someCustomPriority" ); // Clears only the scheduled actions with the given priority

BigBrother.clearScheduledActions(); // Clears all scheduled actions

watch()

Watches for changes in the return value of an expression. It requires two functions as parameters. The first one being the expression to watch, and the second, the callback to trigger when a change is detected. Any call to watch() will automatically initialize the scheduler if it's not running already.


import BigBrother from 'big-brother-js';

let foo = 1;

BigBrother.watch( ()=> foo, value => console.log( "foo has changed, and its value is now ", value ) );

You can watch for changes within an object/array, simply by setting the deepWatch parameter to true:


let fooObj = { foo: 5 };

BigBrother.watch( ()=> return fooObj, value => doSomething(), true ); // Watch for changes within deep nested values of an object

fooObj.foo = 1; // Will trigger the callback

Just like with do() you can schedule to watch for changes using any of your previously defined schedulers by passing its priorityKey as the fourth parameter:


BigBrother.init( 100, "highPriority" );

let foo = 1;

BigBrother.watch( ()=> return foo, ( value )=> doSomething(), false, "highPriority" ); // Will watch for changes every 100 ms

Note: Please keep in mind that the bigger the objects you are watching, the higher amount of resources BigBrother will need in order to keep track of them. So be mindful of this when calling watch(). Keep your expressions specific and your callbacks with the lowest computational complexity possible.

clearWatchers()

Use this method to remove either all watchers, or only those from the selected Scheduler.


BigBrother.clearWatchers( "someCustomPriority" ); // Clears only watchers with the given priority

BigBrother.clearWatchers(); // Clears all watchers

About BigBrother.

This tool is still in development, and there's still a lot to improve. Use at your own peril. If you find any bugs, please open a ticket.

If you feel like giving some feedback or just wish to say hi, [Hit me on twitter]: https://twitter.com/BeardScript