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

recyclex.js

v1.2.0

Published

<p> <img src="https://github.com/concefly/recyclex.js/actions/workflows/ci.yml/badge.svg" alt="CI" /> <img src="https://img.shields.io/npm/dw/recyclex.js" alt="npm" /> <img src="https://img.shields.io/npm/v/recyclex.js" alt="npm" /> </p>

Downloads

131

Readme

recyclex.js

A reactive cycle manager.

  • Responsive property and lifecycle management
  • Zero dependencies

Install

npm install recyclex.js --save

Usage

import { Component, Blueprint, Register } from 'recyclex.js';

@Register('Foo')
class Foo extends Component {
  @Reactive() text = '';

  override onUpdate() {
    return [
      Blueprint.of('Bar', { text: this.text + '_1' }),
      Blueprint.of('Bar', { text: this.text + '_2' }),
      Blueprint.of('Bar', { text: this.text + '_3' }),
    ];
  }
}

@Register('Bar')
class Bar extends Component {
  @Reactive() text = '';

  override onUpdate() {
    console.log(this.text);
  }
}

const host = new Host('Foo');
host.flush({ text: 'Hello' });
host.destroy();

API

Component

override onInit() {...}

Called when the component is initialized.

override onBeforeUpdate() {...}

Called before the component is updated.

override onUpdate() {...}

Called when the component is updated.

if the return value is an array of Blueprint, the children will be init or update or destroy according to the return value, just like the react's render method.

It means:

  • If the child is NEW, it will be initialized.
  • If the child is EXIST, it will be updated.
  • If the child is NOT EXIST anymore, it will be destroyed.

NOTE: The return item is Blueprint, so:

  • Class must be registered.
  • Class will not be initialized, updated or destroyed immediately, but will be added to the update queue, and managed internally.

override onAfterUpdate() {...}

Called after the component is updated.

  • If there is children, it will be called after all children are updated.

override onDestroy() {...}

Called when the component is destroyed.

  • If there is children, it will be called after all children are destroyed.

this._changes: Map<string, any>

A map of changes that have occurred in the component.

  • Key: property name
  • Value: old value

It will be reload before onBeforeUpdate is called.

Register()

Register the class.

import { Register, Component, ComponentRegistry } from 'recyclex.js';

// Register to the default registry
@Register('Foo')
class Foo extends Component {
  // ...
}

// Register to the custom registry
const myRegistry = new ComponentRegistry();
@Register('Bar', myRegistry)
class Bar extends Component {
  // ...
}

Blueprint()

Create a blueprint.

import { Blueprint } from 'recyclex.js';

// Foo is already registered
const blueprint = Blueprint.of('Foo', { text: 'Hello' });

Host()

Create a host.

import { Host } from 'recyclex.js';

// Foo is already registered
const host = new Host('Foo');

// Flush the host with props
host.flush({ text: 'Hello' });

// Destroy the host
host.destroy();

Reactive()

Make the property reactive.

  • If the property is set to a new value, the component will go through the update cycle.
import { Reactive } from 'recyclex.js';

class Foo {
  @Reactive() text = '';
  @Reactive() count = 0;
}