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

angular-dry-scope

v1.0.0

Published

Bringing functional UI paradigms to Angular 1

Downloads

3

Readme

angular-dry-scope

Bringing functional UI paradigms to Angular 1.

Angular Dry Scope helps scope-management code DRY by allowing you to define the value of a scope property in one place, instead of updating it in disjointed parts of the code.

Installation

Install using NPM:

npm install angular-dry-scope --save

Then import it as a module in your Angular app:

angular.module('MyApp', ['dry-scope'])

Usage

1. Define scope properties as functions

$scope.$define('totalCost', function() {
  var costBeforeTax = $scope.items.reduce(function(total, item) {
    return total + item.cost;
  }, 0);

  return costBeforeTax * taxMultiplier;
});

2. Update scope via $update

Don't do this:

$scope.taxMultiplier = 1.08;

Instead, do this:

$scope.$update({
  taxMultiplier: 1.08
});

And $scope.totalCost will automatically be updated!

The Vision

You're an informed Front End web developer. You know to avoid watchers and filters in Angular 1 because they cause performance problems. But you also know that functional programming paradigms (defining your app state using a function instead of "manually" modifying it) are very powerful and allow you to write applications that are easier to read, maintain, and change.

Angular Dry Scope allows you to define scope properties as definition functions that return the value of the property. Definitions are similar in intent, although different in mechanism, to watchers. Watchers say, "when this scope value changes, run this code." Definitions say, "this function will return the correct value of this property at any time." And every time the scope is updated via $update, the definitions are re-run.

When $update is called on a scope, all child scope definitions are re-run, ensuring that any definitions based on inherited scope properties are updated.

See below for more examples.

Best Practices

  1. If you $define a scope property, don't ever set it manually.
  2. Within a component (directive/controller) that uses $define, always use $update to set scope properties.

Purpose and Attribution

This module is an experiment to examine the use of newer functional UI approaches in Angular 1. It was inspired by the state/props model of React.js. $update was shamelessly based on React's setState. Special thanks to @duhduhdan and Tyler Kayser for discussions and ideas that led to this project.