# tablink

> Dispatch data and events to other browser tabs on the same domain.

Latest version **1.0.2** (published 2018-05-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install tablink
pnpm add tablink
yarn add tablink
bun add tablink
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2018-05-09 |
| First published | 2018-05-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Kevin Okerlund |
| Maintainers | kevinokerlund |
| Keywords | dispatch, browser-tab, event, intercom, emit, broadcast, localStorage |

## Links

- npm: https://www.npmjs.com/package/tablink
- npm.io page: https://npm.io/package/tablink

## Dependencies (1)

- [microbundle](https://npm.io/package/microbundle.md) ^0.4.4

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2018-05-09
- 1.0.1 — 2018-05-09
- 1.0.0 — 2018-05-09

## README

# TabLink
Dispatch data and events to other browser tabs on the same domain.

```bash
npm install tablink
```

## API

### Dispatching
Send a message to all other open tabs.
If the optional argument `includeOwnTab` is set to `true`,
the event will also be handled in the current tab doing the dispatching.

```javascript
tablink.dispatch(type, payload[, includeOwnTab]);
```

**`type`**  
A case-sensitive string representing the event type.

**`payload`**  
A string or an object of data. Anything that can be sent through `JSON.stringify/parse`.

**`includeOwnTab`**  
Optional boolean. If `true`, the event will also be handled on the current tab.

**Example:**
```javascript
tablink.dispatch('DISPLAY_LOGOUT_MODAL', {
  type: 'SESSION_TIMEOUT'
}, true);
```

---

### Event listeners

```javascript
tablink.on(type, listener);
```

**`type`**_(String)_  
A case-sensitive string representing the event type to listen for.

**`listener`** _(Function)_  
A callback function that receives the `payload` as its argument.  

To remove the listener, invoke the function returned by `on`.

**Example:**
```javascript
let unsubscribe = tablink.on('DISPLAY_LOGOUT_MODAL', (payload) => {
  showModal(payload.type);
});

// to stop listening
unsubscribe();
```

### Subscribing to all events

```javascript
tablink.subscribe(listener)
```

**`listener`** _(Function)_  
The callback to be invoked any time an action has been dispatched

Adds a change listener. It will be called any time any action is dispatched.
To unsubscribe, invoke the function returned by subscribe.

**Example:**
```javascript
let unsubscribe = tablink.subscribe((type, payload) => {
	switch (type) {
		case 'TEST':
			// When a type of TEST is dispatched...
			break;
	}
});

// To unsubscribe
unsubscribe();
```

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