# tracked-position

> Register a position and strategy so that the coordinates can easily be used by multiple consumers.

Latest version **0.2.0** (published 2015-05-03) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install tracked-position
pnpm add tracked-position
yarn add tracked-position
bun add tracked-position
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2015-05-03 |
| First published | 2015-04-21 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | davetodd |
| Keywords | window, tracked-position |

## Links

- npm: https://www.npmjs.com/package/tracked-position
- Repository: https://github.com/invokes/tracked-position
- Issues: https://github.com/invokes/tracked-position/issues
- npm.io page: https://npm.io/package/tracked-position

## Recent versions

- 0.2.0 (latest) — 2015-05-03
- 0.1.2 — 2015-04-22
- 0.1.1 — 2015-04-21
- 0.1.0 — 2015-04-21

## README

# tracked-position

Create positioning strategies that depend on `window` or `document` events to compute coordinates and then subscribe to events when those coordinates change.

## Why?

This is motivated by a need to share coordinates that may depend on window scroll or resize events between multiple React components. Manually adding a bunch of `window` event handlers inside of `componentDidMount` can get sloppy, so this abstracts that so that you can simply pass in an `x, y` pair as `props` or `state`.

Note that this does not actually have any dependency on React and may be generally useful.

## Getting started

`npm install tracked-position`

### Example usage

Register a position:

    var tracker = require("tracked-position");
    tracker.trackPosition("MY_POSITION", { strategy: "MANUAL", x: 100, y: 100 }, function(coordinates) { 
        // Called on initial track and when coordinates change.
    });

Get the coordinates for the position:

    tracker.getCoordinates("MY_POSITION");
    
Add a custom strategy:

    tracker.addStrategy("CUSTOM_SCROLL_STRATEGY", {
        events: ["scroll"],
        update: function(options, e) {
            return {
                x: window.innerWidth - Math.min(100, window.scrollX);
                y: window.innerHeight - Math.min(100, window.scrollY);
            };
        }
    });

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