<commit_before>observable.ts [![Build Status](https://travis-ci.org/justindujardin/observable.ts.svg?branch=master)](https://travis-ci.org/justindujardin/observable.ts) [![Coverage Status](https://img.shields.io/coveralls/justindujardin/observable.ts.svg)](https://coveralls.io/r/justindujardin/observable.ts?branch=master)
-------------

A reference implementation of the [observable spec](https://github.com/jhusain/observable-spec) in Typescript.

### Example

Define a game trigger object with `enter` and `leave` observables.

```typescript

interface ITrigger {
  enter: obs.Observable;
  leave: obs.Observable;
  doEnter(obj:IPlayer):void;
  doLeave(obj:IPlayer):void;
  destroy():void;
}
interface IPlayer {
  name: string;
  health: number;
}

var player:IPlayer = {
  name: 'MorTon',
  health: 100
};
var trigger:ITrigger = {
  enter: new obs.Observable(),
  leave: new obs.Observable(),
  doEnter: (obj:IPlayer) => trigger.enter.next(obj),
  doLeave: (obj:IPlayer) => trigger.leave.next(obj),
  destroy: () => {
    trigger.enter.return();
    trigger.leave.return();
  }
};

trigger.enter.subscribe({
  next: (value:IPlayer) => {
    var damage = 50;
    value.health -= damage;
    console.log(player.name + ' entered the trigger and took ' + damage + ' damage!');
  }
});
trigger.leave.subscribe({
  next: (value:IPlayer) => {
    console.log(value.name + ' exited the trigger with ' + value.health + ' health remaining.');
  }
});

trigger.doEnter(player);
trigger.doLeave(player);
trigger.destroy();

```

Outputs:
```
MorTon entered the trigger and took 50 damage!
MorTon exited the trigger with 50 health remaining.
```


### License

<p xmlns:dct="http://purl.org/dc/terms/" xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#">
  <a rel="license"
     href="https://creativecommons.org/publicdomain/zero/1.0/">
    <img src="https://i.creativecommons.org/p/zero/1.0/88x31.png" style="border-style: none;" alt="CC0" /><commit_msg>feat(test): add sauce labs matrix execution<commit_after>observable.ts [![Build Status](https://travis-ci.org/justindujardin/observable.ts.svg?branch=master)](https://travis-ci.org/justindujardin/observable.ts) [![Coverage Status](https://img.shields.io/coveralls/justindujardin/observable.ts.svg)](https://coveralls.io/r/justindujardin/observable.ts?branch=master)
-------------

A reference implementation of the [observable spec](https://github.com/jhusain/observable-spec) in Typescript.

### Example

Define a game trigger object with `enter` and `leave` observables.

```typescript

interface ITrigger {
  enter: obs.Observable;
  leave: obs.Observable;
  doEnter(obj:IPlayer):void;
  doLeave(obj:IPlayer):void;
  destroy():void;
}
interface IPlayer {
  name: string;
  health: number;
}

var player:IPlayer = {
  name: 'MorTon',
  health: 100
};
var trigger:ITrigger = {
  enter: new obs.Observable(),
  leave: new obs.Observable(),
  doEnter: (obj:IPlayer) => trigger.enter.next(obj),
  doLeave: (obj:IPlayer) => trigger.leave.next(obj),
  destroy: () => {
    trigger.enter.return();
    trigger.leave.return();
  }
};

trigger.enter.subscribe({
  next: (value:IPlayer) => {
    var damage = 50;
    value.health -= damage;
    console.log(player.name + ' entered the trigger and took ' + damage + ' damage!');
  }
});
trigger.leave.subscribe({
  next: (value:IPlayer) => {
    console.log(value.name + ' exited the trigger with ' + value.health + ' health remaining.');
  }
});

trigger.doEnter(player);
trigger.doLeave(player);
trigger.destroy();

```

Outputs:
```
MorTon entered the trigger and took 50 damage!
MorTon exited the trigger with 50 health remaining.
```
### Browser Support

The observable.ts test suite is run against a number of browsers to ensure it's compatible.

[![Sauce Test Status](https://saucelabs.com/browser-matrix/justindujardin.svg)](https://saucelabs.com/u/justindujardin)

### License

<p xmlns:dct="http://purl.org/dc/terms/" xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#">
  <a rel="license"
     href="https://creativecommons.org/publicdomain/zero/1.0/">
    <img src="https://i.creativecommons.org/p/zero/1.0/88x31.png" style="border-style: none;" alt="CC0" />
{'fraction_non_alphanumeric': 0.17600384707862468, 'fraction_numerical': 0.012022120702091849, 'mean_word_length': 4.333333333333333, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 16, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '694654', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1418, 'n_words': 271}