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

lazycontainer

v1.0.10

Published

LazyContainers for AngularJS allows you to transparently retrieve elements from Arrays or any end-point into a container (the lazyContainer) and easily signal it to load, remove, update, insert, filter, sort, change their look, etc.

Downloads

19

Readme

lazyContainers

LazyContainers are a simple and yet powerful tool. The concept behind lazyContainers is simple, you define a block of content (the lazyContainer), assign to it an iterator (aka lazyIterator) from which it will retrieve the content and just let it do the hard repetitive work for you. Once set up, you will just have to focus on coding your controller to signal the LazyContainer what to do.

Just to mention a few of its features, lazyContainers will take care of transparently retrieving content when signaled from any Array of Objects or almost any remote end-point and build each elements HTML using a directive or template you previously defined. At any given point, you can request the lazyContainer to switch this template/directive for another one and your elements will instantly change their look, you will even be able to filter, sort, update or remove the lazyContainer elements by any of its properties. Let's say you are retrieving content from an end-point which outputs the content un-ordered, lazyContainers can take care of sorting the content transparently for you before loading it. You will, of course, also be able to update/remove or insert elements from within code inside your lazyContainers and assign to any of its actions, which are a lot, your own callbacks to get triggered when these actions are requested which might also decide if they allow or not the action completion.

Installation

 $ npm install lazycontainer lazyiterators

Usage:

lazyContainers are a simply to use and yet very robust AngularJS component in which you will rely almost all the work related with the elements listed in your application and you will simply signal from within your controller what you want it to do so, in this README file i will quickly show you a classic and simply lazyContainer "squeleton" composed by the HTML initializating a lazyContainer and the controller which will signal it to do some simple tasks. For more information, kindly check its full documentation at: http://www.slidonjqueryslider.com/lazycontainer/

In this example, our lazyContainer will be loading its content from within an Array of Objects through an Array iterator called lazyArrayIterator, at any point you can switch the lazyArrayIterator for a lazyEndPointIterator and the elements can be retrieved from almost any HTTP end-point transparently without any sort of code change.

Let's create the HTML with our lazyContainer:

<body ng-app="myApp" ng-controller="myAppController as controller">

    <div ng-if="controller.status.loading.elements">
        Loading content, please wait..
    </div>

    <div ng-if="controller.status.loading.done">
        No more elements in collection
    </div>

    <div ng-if="controller.status.error.elements" ng-click="controller.load = true">
        Error loading content, click to retry
    </div>

    <button ng-click="controller.load = true">LOAD ELEMENTS</button>

    <lazy-container 

        next="controller.load" 
        status="controller.status" 
        config="controller.config"  
        iterator="controller.iterator" >

    </lazy-container>

</body>

As you can see in the previous HTML, lazyContainers will also help you easily inform client when content is loading, there was an error while trying to retrieve the content or there are no more elements to load by simply setting true some of the properties of its status object when any of those conditions happen so you don't even have to bother in adding this UI logic in your controller, lazyContainers will handle this for you.

Finally, we create our Angular module which must require the 'lazyContainer' module (registered when you included/required lazyContainer's file) which will register the lazyContainer directive, then we will create the initial "Config Object" and the lazyIterator our lazyContainer will be using to retrieve content from:


var angular = require('angular');
var LazyIterators = require('lazyiterators');

/* Create Angular App */

var myApp = angular.module("myApp", [require('lazycontainer')]);

/* Create App Controller */

myApp.controller("myAppController", [function() {

    var i, elements = [];

    /* 
     * Initial lazyContainer "Config Object". We tell lazyContainer to
     * use the '/templates/elements.html' template to render each element
     *
     **/

    this.config = {
        elements: {
            template: "/templates/elements.html",
        },
    };

    /* 
     * lazyIterator used by our lazyContainer, we build a list
     * of bogus elements and build a lazyArrayIterator over it.
     *
     **/

    for (i = 0; i < 100; i++) {
        elements.push({
            id: i,
            name: 'element ' + (i + 1),
        });
    }

    this.iterator = new LazyIterators.ArrayIterator(elements);

}]);

You are done! as simple as that, now the lazyContainer will retrieve the content from the lazyArrayIterator (passed via its "iterator" property) each time the user clicks the load button, which simply sets true the "next" lazyContainer parameter signaling it to retrieve a badge of elements from the currenty assigned iterator. The retrieved elements will be rendered using the "/templates/elements.html" template specified in the "Config Object" passed to the lazyContainer in its "config" parameter.

Please note that the parameter used to load elements is called "next" instead of "load" as in the near future you will be able to specify different lazyContainers types which will let you both load content forward (next) and backward (prev).

LazyContainers will set to true the different status properties specified in the "status" object parameter when any of this conditions happen, for example when its loading content from the lazyIterator, there was an error loading the elements or there are no more elements to load from within it. Also note that the user (or your controller from code) can request any number of concurrent loads and the lazyContainer will simply schedule them and set the "loading" property to false once all the loads had been processed (when iterating over an Array this is instant but when doing so with an end-point, connection might delay between requests and lazyContainers will handle this transparently for you). In other words, no more "UI loading/error logic" in your controllers either.

At this point we already have a lazyContainer set up and working, handling for you the loading of content and the UI loading/error reporting logic, kindly check its full documentation at: http://www.slidonjqueryslider.com/lazycontainer/

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the Apache License