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

wires-reactive

v1.1.32

Published

A unique library that watches string template changes and provides a very helpful toolset for watching javascript objects.

Downloads

30

Readme

Build Status IHateReact

Wires Reactive

A unique library that watches string template changes and provides a very helpful toolset for watching javascript objects. It combines 3 libraries:

  • async-watch (to watch variables asynchronously)
  • extract-vars (to extract watchable variables)
  • wires-angular-expressions
import {Watch} from "wires-reactive";
let context = { scope: { user: { name: "Bob" }}}
Watch.template(context, "Hello {{user.name}}!", (str) => {
   // Hello Bob!
});

TRY IT LIVE

How it works

wires-reactive uses async-watch, which adds a very unique and efficient feature to the browser - triggers changes when the browser is actually ready to paint. If you are not familiar with it yet - go ahead, and check it out, this micro solution is unique.

We extract variables from an expression using a very efficient library extract-vars It costs nothing for the browser - non RegEx approach and a tiny size. Besides you can precompile your templates beforehand! Interested how it works> Check a very simple and comprehensive test suite!

We evaluate expressions using angular-expression. Which, unfortunately, is the only options for now. (It understands locals, others - don't)

Features

  • Template expression watch
  • Expression watch (will trigger changes when affected variable is changed)
  • Automatically extracts variables from expressions (intelligent and smart enough to extract only variables that can be possible watched)
  • Written in typescript

Install

npm install wires-reactive

If you want to have it in browser, you have to use your own build, or use include universal files.

inpatient to try it out? clone this repository and just run gulp test-build and open .browser-test-helper/test.html in you favourite browser!

Watch.template

Watches a template, precompiles if necessary. You can pass locals to the context as well.

let context = {
    scope: {
        user: {
            name: "Bob"
        }
    }
}
Watch.template(context, "Hello {{user.name}}! We love you {{user.name}}", (str) => {
   // Hello Bob! We love you Bob
});

Any asynchronous change will trigger a callback. For example

setTimeout(()=> {
  context.scope.user.name = "Richard";
},1)

Please not, that any synchronous call within the current trick won't trigger anything. This behaviour is intentional.

procompileTemplate

In order to speed things up, you can precompile a template

precompileString("Hello {{user.name}}! We love you {{user.name}}")
// Precompiled string:
// [ 'Hello ', [ 'user.name', [ 'user.name' ] ], ', we love you ', [ 'user.name', [ 'user.name' ] ] ]

Watch.expression

Watches an expression, context is the same, should consist of scope and locals (optional)

Watch.expression(context, "{ active : user.name === 'Bob' }", function(result) {
    // {active : true}
});

precompileExpression

Precompile your expressions to make it blazing fast!

precompileExpression("{ active : user.name === 'Bob'"})

I you like this idea, please, don't forget to star the repository. If you think that JSX is the worst what happened to web development, contact me personally via window.atob("c2t5cGU6bmNoYW5nZWQ="), i'll buy you a beer.

Also, we have started a gitter channel (link above)