# raptor-data-providers

> Module to support the optimized delivery of web application resources

Latest version **1.0.1-beta** (published 2014-09-04) · Apache License v2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install raptor-data-providers
pnpm add raptor-data-providers
yarn add raptor-data-providers
bun add raptor-data-providers
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.1-beta |
| Published | 2014-09-04 |
| First published | 2014-02-26 |
| Weekly downloads | 0 |
| License | Apache License v2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Patrick Steele-Idem |
| Maintainers | pnidem, philidem |

## Links

- npm: https://www.npmjs.com/package/raptor-data-providers
- Repository: https://github.com/raptorjs3/raptor-data-providers
- Issues: https://github.com/raptorjs3/raptor-data-providers/issues
- npm.io page: https://npm.io/package/raptor-data-providers

## Dependencies (1)

- [raptor-util](https://npm.io/package/raptor-util.md) ^1.0.0-beta

## Recent versions

- 1.0.1-beta (latest) — 2014-09-04
- 1.0.0-beta — 2014-09-04
- 0.2.4-beta — 2014-07-29
- 0.2.3-beta — 2014-05-05
- 0.2.2-beta — 2014-04-09
- 0.2.1-beta — 2014-03-13
- 0.2.0-beta — 2014-02-26

## README

raptor-data-providers
=====================

The `raptor-data-providers` module provides support for the more efficient and simpler "Pull Model "approach to providing templates with view model data. 

* __Push Model:__ Request all needed data upfront and wait for all of the data to be received before building the view model and then rendering the template.
* __Pull Model:__ Register data providers and immediately start rendering the template. Let the template _pull_ the data needed during rendering.

The Pull Model approach to template rendering requires the use of a templating engine that supports asynchronous template rendering (e.g. [raptor-templates](https://github.com/raptorjs3/raptor-templates) and [dust](https://github.com/linkedin/dustjs)). This is because before rendering the template begins not all of data may have been fully retrieved. Parts of a template that depend on data that is not yet available are rendered asynchronously with the Pull Model approach.

# Push Model versus Pull Model

The problem with the traditional Push Model approach is that template rendering is delayed until _all_ data has been fully received. This reduces the time to first byte, and it also may result in the server sitting idle while waiting for data to be loaded from remote services. In addition, if certain data is no longer needed by a template then only the template needs to be modified and not the controller.

With the new Pull Model approach, template rendering begins immediately. In addition, fragments of the template that depend on data from data providers are rendered asynchronously and wait only on the associated data provider to complete. The template rendering will only be delayed for data that the template actually needs.

# Simple Example

Register data providers upfront:

```javascript
require('raptor-data-providers').register({
    weather: function(args, callback) {
        var zipcode = args.zipcode;
        weatherService.getWeather({
                zipcode: zipcode
            },
            callback);
    });
```

---
_Source: https://npm.io/package/raptor-data-providers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
