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

aurelia-deep-computed

v0.1.7

Published

A plugin to declare deep computed dependencies with ability to watch recursively for changes

Downloads

887

Readme

Aurelia Deep Computed

Installation

npm install aurelia-deep-computed

then in your app entry:

import { PLATFORM } from 'aurelia-framework';

export function configure(aurelia: Aurelia) {
  aurelia.use.plugin(PLATFORM.moduleName('aurelia-deep-computed'));
  // Or, for `aurelia-framework` 1.3 & later, you can do instead:
  // aurelia.use.plugin(configureDeepComputed);
}

Usage example

There are 2 mains exports of this plugin: deepComputedFrom and shallowComputedFrom. Following is an example of the difference between 2 decorators, when the result of computedExpression (data in the following example) is an object:

class App {

  data = { name: { first: 'bi', last: 'go' }, address: { number: 80, unit: 9 } }

  @deepComputedFrom('data')
  get contactDeep() {
    return JSON.stringify(this.data);
  }

  @shallowComputedFrom('data')
  get contactShallow() {
    return JSON.stringify(this.data);
  }
}

and template:

Deep: ${contactDeep}

Shallow: ${contactShallow}

Rendered text will be:

{"name":{"first":"bi","last":"go"},"address":{"number":80,"unit":9}}

{"name":{"first":"bi","last":"go"},"address":{"number":80,"unit":9}}
  1. When modify first name with:
app.data.name.first = 'b'

Rendered text will be:

{"name":{"first":"b","last":"go"},"address":{"number":80,"unit":9}}

// no change on this, because it doesn't observe deeper than the first level
// which are properties "name" and "address"
{"name":{"first":"bi","last":"go"},"address":{"number":80,"unit":9}}
  1. When modify name with:
app.data.name = { first: 'b', last: 'c' }

Rendered text will be:

{"name":{"first":"b","last":"g"},"address":{"number":80,"unit":9}}

// no change on this, because it doesn't observe deeper than the first level
// which are properties "name" and "address"
{"name":{"first":"b","last":"g"},"address":{"number":80,"unit":9}}

With cache:

One of the problems with getter function is that the value the function will be executed everytime the property is accessed. This could be an issue if the getter function takes a lot of time to complete. This plugin provides a way to overcome this, with an option name cache. If cache is on, the observer created for a getter function will assume that the value of the getter function will solely depend on the dependencies you gave it. And with this assumption, the observer will be able to efficiently cache the value from the last time it ran the getter function, unless there has been some changes in one of its observed dependencies.

One important caveat of this is that it will only cache when it has start observing. This typically means if the view model/model that has an computed observer and is not yet connected to a view, it will still execute the getter function every time the property is accessed, as it cannot safely assume otherwise.

An example of cache usage would be:

class App {

  data = { name: { first: 'bi', last: 'go' }, address: { number: 80, unit: 9 } }

  @deepComputedFrom({
    deps: ['data'],
    cache: true
  })
  get contactDeep() {
    console.log('deep');
    return JSON.stringify(this.data);
  }

  @shallowComputedFrom({
    deps: ['data'],
    cache: true
  })
  get contactShallow() {
    console.log('shallow');
    return JSON.stringify(this.data);
  }
}

After the observer started observing, no matter how many times you read contactDeep or contactShallow properties, console.log('deep') or console.log('shallow') will be called only once.

Notes

Both decorator exports of this pluginare dropin replacement for built-in decorator computedFrom, as following example:

Instead of:

import { computedFrom } from 'aurelia-framework';

class App {

  data = { firstName: 'Bi', lastName: 'pon', middleName: 'go' }

  @computedFrom('data')
  get fullName() {
    return JSON.stringify(this.data);
  }
}
import { deepComputedFrom } from 'aurelia-deep-computed';

export class App {

  data = { firstName: 'Bi', lastName: 'pon', middleName: 'go' }

  @deepComputedFrom('data')
  get fullName() {
    return JSON.stringify(this.data);
  }

  // or
  @shallowComputedFrom('data')
  get fullName() {
    return JSON.stringify(this.data);
  }
}