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

drpx-updateable

v0.1.0

Published

Simple Angular tool to eventually broadcast message when a component is updated

Downloads

8

Readme

drpx-updateable

Simple Angular tool to eventually broadcast message when a component is updated.

Why? Because in some cases we need to perform some complex derived computations and we want to keep all recalculation process simple, safe, and efficient.

Updateable is designed to:

  • maintain always data integrity: because update does not provides extra information about what is changed, all must be recomputed (in angular style), so only one point to maintain

  • scalable functionality: because update does not provides information about which operation is done, all must be recomputed so it does not matter if new method/option/whatever is added

  • efficient: updateable runs asyncronous debounced, so even if multiple calls to update are performed (ex: a bulk addition of data) event is triggered once, so only one recomputation is required

  • integrated with digest loop: all updates are performed inside a digest loop, no need for $scope.$apply() or whatever,

  • almost no garbage left: update events are handled by angular $broadcast, so controllers/... can handle it by listenting from their own $scope which listener is destroyed along its $scope when it is not longer required

  • simplicity: just do $scope.$on('yourEvent', function() { ... }) and recompute what you need, no more register/unregister/...

Install

$ bower install --save drpx-updateable

add to your module the dependence:

    angular.module('yourModule', ['drpxUpdateable']);

include the javascript library in your application:

<script src="bower_components/drpx-updateable/drpx-updateable.js"></script>

How to use

Inside your service state:

    yourServiceFactory.$inject = ['drpxUpdateable'];
    function yourServiceFactory  ( drpxUpdateable ) {
        var service = {
            change: change,
            // your other methods

            update: drpxUpdateable('yourUpdate')
        }

        function change(...) {
            // do your changes
            service.update();
        }

        return service;
    }

Check A: Listen for changes in your controller:

    YourController.$inject = ['yourService','$scope'];
    function YourController  ( yourService , $scope ) {
        $scope.$on('yourUpdate', update.bind(this));

        function update() {
            this.data = yourService.data;            
        }
    }

Check B: Listen for changes in your derived service /store:

    yourDerivedServiceFactory.$inject = ['yourService','$rootScope'];
    function yourDerivedServiceFactory  ( yourService , $rootScope ) {
        var service = {
            data: null,
            // your other methods
        }

        $rootScope.$on('yourUpdate', update);
        update();

        function update() {
            service.data = yourService.computeDerived();
        }

        return service;
    }

Note

Implementation takes advantage of current angular event implementation. It means that you have to recall the name of the event broadcasted and you should have a good event name nomenclature. It should be no necessary to put event constants inside a variable, for example: yourService.updateEvent or EVENTS.yourUpdate, because Javascript does not checks if that property exists and no wanrning should be raised if it changes. So, if you have a good nomenclature you should use string directly. My recommendation is event name like: '{moduleName}.{serviceName}Update'.