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

@kreatio/inflight

v0.1.3

Published

*Please read this documentation at https://kreatio-sw.github.io/inflight/*

Downloads

4

Readme

In Flight

Please read this documentation at https://kreatio-sw.github.io/inflight/

Motivation

Single Page Applications (SPA) pose unique issues which conventional applications did not face. In an SPA, quite often the following situation is faced:

  • There is a list of entities to be displayed.
  • There are several links that will impact the selection criteria.
  • There may be a search box that will further impact the selection criteria.

A pragmatic approach can be as follows:

  • When switching selection criteria, the previous query, which may still be in flight, needs to be canceled.

  • Even the it could not be canceled it needs to be ensured that stale data does not show up in the UI (may happen if not implemented correctly).

  • Regarding entries already displayed, while switching there may be several scenarios:

    • clear the current entries as soon a switch is requested.
    • do not clear, but prevent users from interacting with these.
    • do not clear, let users interact as well.
    • indicate users that a switch is in progress.
  • Needs to simplify loading subsequent pages:

    • should indicate when a page is getting loaded.
    • should manage a switch even when a page is getting loaded.
    • must load pages in order.
    • should not load the same page twice.
  • Ideally distinguish when no data has arrived from no entities matched the criteria.

  • Allows updating entities locally:

    • updating some attributes.
    • adding new entities.
    • deleting entities.

Well, this library targets to simplify the above in simple and consistent ways.

Supported State Flags

See InFlightState for more details:

  • dataLoaded - will be set when data is loaded, this flag will help in distinguishing empty data from the state when no data is loaded yet.
  • inFlight - when data has been requested but not yet arrived.
  • switchInProgress - will provide additional qualification when data source/criteria is changing. This can be used to indicate the user that current data is stale or even putting a glass panel to block interaction.
  • errored - set to true when an error has occurred, will be cleared when a subsequent request is made.
  • hasMorePages set to true if there are more pages expected. It takes care of few edge cases, see specs for details. One important one is a case when the backend actually returns lesser results than what it initially said it would.

Considerations for local updates

These issues are not specific to this library and not solved by this library.

Local updates when combined with pagination can get quite tricky.

Consider the cases when not all entities are loaded in the UI yet.

  • Inserts:

    • Where to place the newly created entries

      • beginning
      • end
      • in the correct sort order (may not be possible as all matching entities are not loaded yet)
    • what to do if newly created entity does not match the current selection criteria

    • what to do if the newly added entities shows up on a subsequently added page

  • Update:

    • what if the update changes the position of the entity as per the sort order
    • what if the entity no longer matches the selection criteria
  • Delete:

    • will the pagination still work (i.e. subsequent pages will load correctly)
    • what if the entities get reloaded even before the delete got carried out in the data store.

Install

Add npm package to your Angular4/Angular5 project:

$ npm -i @kreatio/inflight

# or

$ yarn add @kreatio/inflight

All classes are plain typescript classes, so you need not mention or provide any of these in your project.

Usage

See the following for API details:

Basic usage

    const inFlight = new InFlight();

    // This will be passed to the function that gets actual data
    const perPage = 25;
    
    // If set to true it will clear the data before issuing next
    // request. Setting flase will cause the data to chnage when
    // first page of new request arrives.
    const clearData = true;
    
    inFlight.start(perPage, clearData, (page, perPage) => {
      return getAllImages(page, perPage);
    });
    
    inFlight.stateObservable.subscribe((state: InFlightState) => {
      // Will yield for every state change
    });
    
    // You can use state directly as a variable for binding
    let dataInFlight = inFlight.state.inFlight;
    let dataLoaded = inFlight.state.dataLoaded;
    
    inFlight.resultsObservable.subscribe((results:PagedResults) => {
      // Will yield whenever results change
      let totalResults = results.total;
      let currentPage = results.page;
      let entities = results.entities;
    });
    
    // Load additional page if there are more pages
    if(inFlight.state.hasMorePages) {
      inFlight.getNextPage();
    }
    
    // To switch the list entirely call start again with new criteria
    inFlight.start(5, true, (page, perPage) => {
      return getMyImages(page, perPage);
    });

Implementing the data request function

It should return an Observable that should yield a PagedResults. Typically it will be a get call on one of the Angular HTTP classes with potential chaining of map calls. The returned Observable should yield only once.

Developing

  • src/app/inflight/gen-mock-data.spec.ts - part of testing framework, generates test data with an optional delay
  • src/app/inflight/inflight-state.ts - structure for state
  • src/app/inflight/inflight-*.spec.ts - test cases
  • src/app/inflight/inflight.ts - main code
  • src/app/interfaces/paged-results.ts - structure for paged results

Test cases have good coverage - has actually been more complex to develop than the actual functionality. Mock Data Generator has test cases of its own which are set to skip by default.

Beware test cases take significant time to run as these need to test delays and errors.

$ ng test