Skip to content

Commit

Permalink
Finish release-1-0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondra Machala committed May 11, 2018
2 parents 2169e15 + a43ad30 commit 857f1f8
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 85 deletions.
1 change: 1 addition & 0 deletions .travis.yml
@@ -1,3 +1,4 @@
language: node_js
node_js:
- "stable"
script: npm run cover
93 changes: 47 additions & 46 deletions README.md
Expand Up @@ -3,80 +3,81 @@
Javascript (typescript) implementation of observer pattern on less then 100 rows.
It provides just o few most common functions and minified version is smaller then 2kB.

[![Build Status](https://travis-ci.org/omachala/slim-observer.svg?branch=master)](https://travis-ci.org/omachala/slim-observer)
[![Coverage Status](https://coveralls.io/repos/github/omachala/slim-observer/badge.svg?branch=master)](https://coveralls.io/github/omachala/slim-observer?branch=master)
[![Travis](https://img.shields.io/travis/omachala/slim-observer.svg)](https://travis-ci.org/omachala/slim-observer)
[![Coveralls github](https://img.shields.io/coveralls/github/omachala/slim-observer.svg)](https://coveralls.io/github/omachala/slim-observer)
![GitHub package version](https://img.shields.io/github/package-json/v/omachala/slim-observer.svg)

## Building tools
## Usage

### Lint
Linting using tslint.
Basic usage
```js
// create observable subject
var observable = new Subject();

```
npm run lint
```
// create first listener
observable.subscribe(function(newValue){
alert(newValue);
});

### Clean
Clear the `dist/` folder.
// create second listener
observable.subscribe(function(newValue){
console.log(newValue);
});

```
npm run clean
observable.next('hello'); // emit value to all listeners
observable.next('world'); // emit another value
```

### Build
Transpile TS code to JS in `dist/` folder. Maps included.
Get last emitted value
```js
observable.getLast();
```

Create subject with initial value
```js
var observable = new Subject('initial value');
```
npm run build

New subscriber with all history values replay.
```js
observable.replayAndSubscribe(function(newValue){
console.log(newValue);
});
```

Continous build:
Unsubscribe existing listener.
```js
var observable = new Subject();

var subscriber = observable.subscribe(function(newValue){
alert(newValue);
});

subscriber.unsubscribe();
```
npm run build:w

Emitting only unique values (if new value is different).
```js
observable.nextUnique(123).nextUnique(123); // emits value to subscribers only once
```

### Uglify
Concat and minify all JS files in `dist/` folder to one output (default `dist/all.min.js`).
## Building tools

### Build
Transpile TS code to JS in `dist/` folder. Maps included.
```
npm run uglify
npm run build
```

### Unit Test
Tests framework used are: mocha & chai.

TDD mode to run it concurrently with your editions:

```
npm run test:tdd
```

CI mode to run it only one:

```
npm test
```

Testing with coverage:

```
nyc npm test
nyc report -r text lcov html
coverage/index.html
```


### Coverage Test
TDD mode to run it concurrently with your editions:

```
npm run test:tdd
```

CI mode to run it only one:

```
npm run test
```

## License
Expand Down
3 changes: 0 additions & 3 deletions dist/interfaces.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/interfaces.js.map

This file was deleted.

2 changes: 1 addition & 1 deletion dist/slim-observer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/subject.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions package.json
@@ -1,8 +1,8 @@
{
"name": "ts-project-seed",
"version": "1.0.2",
"description": "A seed project with the initial plumbing for TypeScript.",
"main": "index.js",
"name": "slim-observer",
"version": "1.0.0",
"description": "Slim javascript observer pattern implementation.",
"main": "dist/slim-observer.min.js",
"scripts": {
"clean": "rimraf dist",
"build": "npm run clean && npm run lint && tsc -p tsconfig.json && npm run uglify",
Expand All @@ -11,18 +11,18 @@
"lint": "tslint -c tslint.json 'src/**/*.ts'",
"test:tdd": "mocha --reporter min --require ts-node/register \"src/**/*.spec.ts\" --watch",
"test": "mocha --recursive --require ts-node/register \"src/**/*.spec.ts\"",
"cover": "nyc npm test"
"cover": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
},
"repository": {
"url": "https://github.com/metadevpro/ts-project-seed"
"url": "https://github.com/omachala/slim-observer"
},
"keywords": [
"typescript",
"scaffolding"
"observer"
],
"author": {
"name": "Pedro J. Molina",
"url": "http://pjmolina.com"
"name": "Ondrej Machala",
"url": "https://github.com/omachala"
},
"license": "CC0-1.0",
"nyc": {
Expand Down Expand Up @@ -53,7 +53,9 @@
"@types/mocha": "^5.0.0",
"@types/node": "^9.3.0",
"chai": "^4.1.2",
"coveralls": "^3.0.1",
"mocha": "^5.0.0",
"mocha-lcov-reporter": "^1.3.0",
"nyc": "^11.4.1",
"rimraf": "^2.6.2",
"ts-node": "^5.0.0",
Expand Down
23 changes: 0 additions & 23 deletions src/interfaces.ts

This file was deleted.

22 changes: 21 additions & 1 deletion src/subject.ts
@@ -1,6 +1,26 @@
'use strict';

import {IListener, ISubject, ISubscriber} from "./interfaces";
export interface ISubscriber {
unsubscribe();
}

export interface IListener {
_id: any;

callback(data?: any);
}

export interface ISubject {
getLast(): any;

next(data?: any): ISubject;

nextUnique(data?: any): ISubject;

subscribe(callback: Function): ISubscriber;

replayAndSubscribe(callback: Function): ISubscriber;
}

export class Subject implements ISubject {

Expand Down

0 comments on commit 857f1f8

Please sign in to comment.