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

@holochain-open-dev/signals

v0.300.0-dev.8

Published

Holochain async-signals to build reusable holochain-open-dev modules

Downloads

719

Readme

@holochain-open-dev/signals

Re-export of signal-polyfill and async-signals, with some additional utilities targeted to build holochain apps on top of it.

These are the additional utilities added by this package:

immutableEntrySignal

Fetches the given entry, retrying if there is a failure.

Makes requests only the first time it is watched, and will stop after it succeeds in fetching the entry.

Whenever it succeeds, it caches the value so that any subsequent requests are cached.

Useful for entries that can't be updated.

import { Link } from '@holochain/client';
import { LazyHoloHashMap, EntryRecord } from '@holochain-open-dev/utils';
import { AsyncSignal, immutableEntrySignal } from '@holochain-open-dev/signals';

import { PostsClient } from './posts-client.js';
import { Post } from './types.js';

export class PostsStore {

  constructor(public postsClient: PostsClient) {}

  posts: LazyHoloHashMap<ActionHash, EntryRecord<Post>> = new LazyHoloHashMap((postHash: ActionHash) => 
    immutableEntrySignal(() => this.postsClient.getPost(postHash))
  );
}

latestVersionOfEntrySignal

Keeps an up to date copy of the latest version of an entry, making requests only while it has some watcher.

Will do so by calling the given every 20 seconds calling the given fetch function, and listening to EntryUpdated signals.

Useful for entries that can be updated.

import { Link } from '@holochain/client';
import { LazyHoloHashMap, EntryRecord } from '@holochain-open-dev/utils';
import { AsyncSignal, latestVersionOfEntrySignal } from '@holochain-open-dev/signals';

import { PostsClient } from './posts-client.js';
import { Post } from './types.js';

export class PostsStore {

  constructor(public postsClient: PostsClient) {}

  posts: LazyHoloHashMap<ActionHash, EntryRecord<Post>> = new LazyHoloHashMap((postHash: ActionHash) => 
    latestVersionOfEntrySignal(
      this.postsClient, // Give the client so that it can listen to the `EntryUpdated` signal
      () => this.postsClient.getLatestPost(postHash)), // Fetch the latest version of the post
  );
}

allRevisionsOfEntrySignal

Keeps an up to date list of all the revisions for an entry, making requests only while it has some subscriber.

Will do so by calling the given every 20 seconds calling the given fetch function, and listening to EntryUpdated signals.

Useful for entries that can be updated.

import { Link } from '@holochain/client';
import { LazyHoloHashMap, EntryRecord } from '@holochain-open-dev/utils';
import { AsyncSignal, allRevisionsOfEntrySignal } from '@holochain-open-dev/signals';

import { PostsClient } from './posts-client.js';
import { Post } from './types.js';

export class PostsStore {

  constructor(public postsClient: PostsClient) {}

  posts: LazyHoloHashMap<ActionHash, Array<EntryRecord<Post>>> = new LazyHoloHashMap((postHash: ActionHash) => 
    allRevisionsOfEntrySignal(
      this.postsClient, // Give the client so that it can listen to the `EntryUpdated` signal
      () => this.postsClient.getAllRevisionsForPost(postHash)), // Fetch all the revisions for the post
  );
}

deletesForEntrySignal

Keeps an up to date list of the deletes for an entry, making requests only while it has some subscriber.

Will do so by calling the given every 20 seconds calling the given fetch function, and listening to EntryDeleted signals.

Useful for entries that can be deleted.

import { Link } from '@holochain/client';
import { LazyHoloHashMap, EntryRecord } from '@holochain-open-dev/utils';
import { AsyncSignal, deletesForEntrySignal } from '@holochain-open-dev/signals';

import { PostsClient } from './posts-client.js';
import { Post } from './types.js';

export class PostsStore {

  constructor(public postsClient: PostsClient) {}

  posts: LazyHoloHashMap<ActionHash, Array<SignedActionHashed<Delete>>> = new LazyHoloHashMap((postHash: ActionHash) => 
    deletesForEntrySignal(
      this.postsClient, // Give the client so that it can listen to the `EntryDeleted` signal
      postHash, // Hash of the original `Create` action
      () => this.postsClient.getAllDeletesForPost(postHash)), // Fetch all the delete actions for the post
  );
}

collectionSignal

Keeps an up to date list of the targets for the non-deleted links for the given collection in this DHT, making requests only while it has some subscriber.

Will do so by calling the given every 20 seconds calling the given fetch function, and listening to LinkCreated and LinkDeleted signals.

Useful for collections

import { Link } from '@holochain/client';
import { AsyncSignal, collectionSignal } from '@holochain-open-dev/signals';

import { PostsClient } from './posts-client.js';

export class PostsStore {

  constructor(public postsClient: PostsClient) {}

  allPostsSignal: AsyncSignal<Array<Link>> = collectionSignal(
    this.postsClient,
    async () => this.postsClient.getAllPosts(), // Request to fetch the initial list of posts
    "AllPosts", // Link type for the collection
  );
}

liveLinksSignal

Keeps an up to date list of the links for the non-deleted links in this DHT, making requests only while it has some subscriber.

Will do so by calling the given fetch callback every 20 seconds, and listening to LinkCreated and LinkDeleted signals.

Useful for link types.

import { Link } from '@holochain/client';
import { AsyncSignal, collectionSignal } from '@holochain-open-dev/signals';

import { PostsClient } from './posts-client.js';

export class PostsStore {

  constructor(public postsClient: PostsClient) {}

  myPostsSignal: AsyncSignal<Array<Link>> = liveLinksSignal(
    this.postsClient,
    this.postsClient.client.myPubKey, // Base address for the links
    () => this.postsClient.getMyPosts(), // Fetch the live links
    'AuthorToPosts', // Link type
  );
}

deletedLinksSignal

Keeps an up to date list of the targets for the deleted links in this DHT, making requests only while it has some subscriber.

Will do so by calling the given every 20 seconds calling the given fetch function, and listening to LinkDeleted signals.

Useful for link types and collections with some form of archive retrieving functionality

import { Link } from '@holochain/client';
import { AsyncSignal, collectionSignal } from '@holochain-open-dev/signals';

import { PostsClient } from './posts-client.js';

export class PostsStore {

  constructor(public postsClient: PostsClient) {}

  myDeletedPostsSignal: AsyncSignal<Array<[SignedActionHashed<CreateLink>, Array<SignedActionHashed<DeleteLink>>]>> = deletedLinksSignal(
    this.postsClient,
    this.postsClient.client.myPubKey, // Base address for the links
    () => this.postsClient.getMyDeletedPosts(), // Fetch the deleted links 
    'AuthorToPosts', // Link type
  );
}