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

@resin-js/core

v0.2.3

Published

A lightweight reactive library for native web development. Resin provides reactivity, enhancing vanilla JavaScript applications.

Downloads

458

Readme

Resin.js

A lightweight reactive library for native web development. Resin provides reactivity, enhancing vanilla JavaScript applications.

Features

  • 🎯 Zero-dependency DOM binding
  • 🔄 Simple, powerful state management
  • 📦 No build step required
  • 🎨 Framework-agnostic
  • 🚀 Predictable performance
  • 🎭 TypeScript-first

Installation

npm install @resin-js/core

Basic Usage

import { resin, bind } from '@resin-js/core';

// Create reactive state
const counter = resin(0);

// Bind to DOM
bind(document.querySelector('.counter'), counter);

// Updates automatically
counter.value++; // DOM updates instantly

Core Concepts

State Management

// Simple values
const count = resin(0);

// Complex objects
const user = resin({
    name: 'John',
    settings: {
        theme: 'dark',
        notifications: true
    }
});

// Arrays
const todos = resin([
    { id: 1, text: 'Learn Resin', done: false }
]);

// Maps
const userMap = resin(new Map());

DOM Binding

// Basic binding
bind(element, state);

// Conditional rendering
bind(element, state, {
    if: value => value > 0
});

// Value transformation
bind(element, state, {
    map: value => `Count: ${value}`
});

// Class bindings
bind(element, state, {
    class: {
        'active': value => value.isActive,
        'disabled': value => !value.isEnabled
    }
});

// Attribute bindings
bind(element, state, {
    attr: {
        'disabled': value => !value.isValid,
        'aria-expanded': value => value.isOpen
    }
});

Array Operations

const todos = resin([
    { id: 1, text: 'Learn Resin', done: false },
    { id: 2, text: 'Build app', done: true }
]);

// Reactive filtering
const activeTodos = todos.filterResin(todo => !todo.done);

// Reactive mapping
const todoTexts = todos.mapResin(todo => todo.text);

// Reactive find
const firstActive = todos.findResin(todo => !todo.done);

// Sorted view
const sortedTodos = todos.sortedResin((a, b) => a.id - b.id);

// Regular array operations work too
todos.value.push({ id: 3, text: 'New todo', done: false });

Map Operations

const users = resin(new Map([
    ['user1', { name: 'John', age: 30 }]
]));

// Reactive get
const user1 = users.getResin('user1');

// Reactive entries
const entries = users.entriesResin();

// Regular Map operations work
users.value.set('user2', { name: 'Jane', age: 25 });

Event Handling

state.on('init', ({ value }) => {
    console.log('Initial value:', value);
});

state.on('change', ({ value, oldValue }) => {
    console.log('Value changed:', oldValue, '->', value);
});

state.on('error', ({ error }) => {
    console.error('Error occurred:', error);
});

Computed Values

import { computed } from '@resin-js/core';

const firstName = resin('John');
const lastName = resin('Doe');

const fullName = computed(() => 
    `${firstName.value} ${lastName.value}`
);

Batch Updates

import { batch } from '@resin-js/core';

batch(() => {
    state1.value = newValue1;
    state2.value = newValue2;
    // DOM updates once at the end
});

Advanced Features

Persistence

const settings = resin({
    theme: 'light'
}, {
    persist: {
        key: 'app-settings',
        // Optional custom serialization
        serialize: JSON.stringify,
        deserialize: JSON.parse
    }
});

Validation

const form = resin({
    email: ''
}, {
    validate: value => ({
        valid: value.email.includes('@'),
        error: 'Invalid email format'
    })
});

Transform Pipeline

const input = resin('', {
    transform: [
        value => value.trim(),
        value => value.toLowerCase()
    ]
});

Use Cases

  • Enhanced vanilla JavaScript applications
  • Progressive enhancement of existing sites
  • Small to medium web applications
  • Form handling
  • Dynamic UI updates
  • Real-time data display
  • Interactive components

Why Resin?

  • Simple Mental Model: Just state and bindings
  • Progressive Enhancement: Add reactivity where needed
  • Framework Freedom: Works with any JavaScript code
  • Type Safety: Full TypeScript support
  • Predictable Updates: Direct DOM manipulation
  • Small Learning Curve: Familiar JavaScript patterns

Browser Support

Supports all modern browsers (ES2015+).

License

MIT

Contributing

Contributions welcome! Please read our contributing guidelines and code of conduct.

Packages

  • @resin-js/core: Core reactivity system