Skip to content

Commit f1b5a1b

Browse files
committed
Merge tag '0.3.2'
v0.3.2
2 parents 49ede99 + 8765387 commit f1b5a1b

37 files changed

+277
-155
lines changed

README.md

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,6 @@ npm i servable --save
1010

1111
---------
1212

13-
It can be used like so:
14-
15-
```
16-
const Observable = require('servable').Observable;
17-
18-
const countObservable$ = Observable.interval(1000, 1);
19-
20-
const countSubscription = countObservable$
21-
.take(10)
22-
.map((n) => n * 5)
23-
.filter((n) => n > 10)
24-
.subscribe({
25-
next (number) {
26-
console.log('NEXT NUMBER: ', number);
27-
},
28-
29-
error (errors) {
30-
console.warn('I HAVE ERRORS', errors)
31-
},
32-
33-
complete () {
34-
console.log('I AM COMPLETE');
35-
}
36-
});
37-
```
38-
39-
This will log out to the console (if subscribe like above is called):
40-
```
41-
NEXT NUMBER: 15
42-
NEXT NUMBER: 20 // after a 1 second delay
43-
NEXT NUMBER: 25 // after a 1 second delay
44-
NEXT NUMBER: 30 // after a 1 second delay
45-
NEXT NUMBER: 35 // after a 1 second delay
46-
NEXT NUMBER: 40 // after a 1 second delay
47-
NEXT NUMBER: 45 // after a 1 second delay
48-
NEXT NUMBER: 50 // after a 1 second delay
49-
I AM COMPLETE // same time as previous line
50-
```
51-
5213
### There a few plugins that are available - each return a new Observable instance
5314

5415
- [Documentation on the plugin operators can be seen here](./src/operators/DOCUMENTATION.md)

example/adder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// same example as https://github.com/cujojs/most#simple-example
22

3-
const { fromEvent, combineLatest } = Servable;
3+
const { fromEvent, combine } = Servable;
44

55
const xInput = document.querySelector('input.x');
66
const yInput = document.querySelector('input.y');
@@ -22,7 +22,7 @@ const main = () => {
2222
const y = fromEvent('input', yInput).map(toNumber);
2323

2424
// result is the live current value of adding x and y
25-
const result = combineLatest(x, y, add);
25+
const result = combine([x, y], add);
2626

2727
// Observe the result value by rendering it to the resultNode
2828
result.subscribe(renderResult);

example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h3>Adder</h3>
1818
</form>
1919
</div>
2020

21-
<script type="text/javascript" src="../dist/index.min.js"></script>
21+
<script type="text/javascript" src="../dist/index.js"></script>
2222
<script type="text/javascript" src="index.js"></script>
2323
<script type="text/javascript" src="adder.js"></script>
2424
</body>

example/index.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
const { Observable } = Servable;
22

3-
const countObservable$ = Observable.interval(1000, 1);
4-
5-
const countSubscription = countObservable$
6-
.take(10)
7-
.map((n) => n * 5)
8-
.filter((n) => n > 10)
9-
.combineLatest(
10-
countObservable$
11-
.take(5)
12-
)
3+
const countObservable$ = Observable.interval(1000, 1).take(4);
4+
const countObservable2$ = Observable.interval(500, 5);
5+
6+
const countSubscription =
7+
Observable.zip([
8+
countObservable$,
9+
countObservable2$.take(7),
10+
countObservable$,
11+
countObservable2$.take(7),
12+
])
13+
// countObservable2$.take(5)
1314
.subscribe({
1415
next (number) {
1516
console.log('NEXT NUMBER: ', number);
@@ -20,7 +21,7 @@ const countSubscription = countObservable$
2021
},
2122

2223
complete () {
23-
console.log('I AM COMPLETE');
24+
console.trace('I AM COMPLETE');
2425
}
2526
});
2627

@@ -39,3 +40,13 @@ inputObservable$
3940
inputObservable$
4041
.do((text) => div.textContent = text)
4142
.subscribe();
43+
44+
Observable
45+
.ajax('../package.json')
46+
.do(console.log.bind(console.log, 'response'))
47+
.flatMap(response => Observable.fromPromise(response.json()))
48+
.do(console.log.bind(console.log, 'value'))
49+
.subscribe({
50+
next: (value) => console.log(value),
51+
error: (e) => console.warn(e, e.response)
52+
});

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "servable",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"description": "From scratch observable",
55
"main": "lib/index.js",
66
"jsnext:main": "src/index.js",
77
"scripts": {
88
"test": "echo \"Error: no test specified\" && exit 0",
99
"build": "rimraf lib dist && buba src -o lib && rollup -c && uglifyjs dist/index.js -c \"warnings=false\" --comments -m -o dist/index.min.js --verbose",
1010
"watch": "rollup -c -w",
11-
"release": "node release.js"
11+
"release": "node release.js",
12+
"server": "http-server"
1213
},
1314
"repository": {
1415
"type": "git",
@@ -22,13 +23,15 @@
2223
"homepage": "https://github.com/maniator/servable#readme",
2324
"devDependencies": {
2425
"buba": "^4.0.2",
26+
"http-server": "^0.10.0",
2527
"inquirer": "^3.0.6",
2628
"rimraf": "^2.6.1",
2729
"rollup": "^0.41.6",
2830
"rollup-plugin-buble": "^0.15.0",
31+
"rollup-plugin-filesize": "^1.3.2",
2932
"rollup-plugin-license": "^0.3.0",
33+
"rollup-plugin-node-globals": "^1.1.0",
3034
"rollup-plugin-node-resolve": "^3.0.0",
31-
"rollup-plugin-sizes": "^0.3.0",
3235
"rollup-watch": "^3.2.2",
3336
"semver": "^5.3.0",
3437
"shelljs": "^0.7.7",

rollup.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import buble from 'rollup-plugin-buble';
22
import nodeResolve from 'rollup-plugin-node-resolve';
3-
import sizes from 'rollup-plugin-sizes';
3+
import filesize from 'rollup-plugin-filesize';
44
import license from 'rollup-plugin-license';
5+
import globals from 'rollup-plugin-node-globals';
56

67
const pkg = require('./package.json');
78

@@ -18,7 +19,8 @@ export default {
1819
sourceMap: true,
1920
plugins: [
2021
buble(),
21-
sizes(),
22+
filesize(),
23+
globals(),
2224
license({
2325
banner,
2426
}),

src/Observer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class Observer {
3636
use (callback) {
3737
return this.catchErrors(() => {
3838
const response = callback({
39-
next: (...args) => this.onNext(...args),
39+
next: (value) => this.onNext(value),
4040
error: (...errors) => this.onError(...errors),
4141
complete: () => this.onComplete(),
4242
});
@@ -57,9 +57,9 @@ export class Observer {
5757
return this.setupObserver(next);
5858
}
5959

60-
this.onNext = this.catchErrors((...args) => {
60+
this.onNext = this.catchErrors((value) => {
6161
if (!this.isComplete) {
62-
return next(...args);
62+
return next(value);
6363
}
6464
});
6565

src/Subject.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ export class Subject {
4444
return this;
4545
}
4646

47-
next (...args) {
47+
next (value) {
4848
this.cleanup((observer) => {
49-
observer.onNext(...args);
49+
observer.onNext(value);
5050
});
5151
}
5252

src/observables.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './observables/ajax';
12
export * from './observables/fromEvent';
23
export * from './observables/fromPromise';
34
export * from './observables/range';

src/observables/DOCUMENTATION.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
These methods are called by doing: `Observable.<observableFunction>`
22

3+
`.ajax(url[, options])`
4+
5+
- an observable wrapper around the `fetch` API
6+
- you can add a shim like [this one](https://github.com/github/fetch) if your environment does not have the fetch api
7+
38
`.fromEvent(<eventName>, <element>[, <mapCallback>)`
49

510
- will create an observable that will listen for an event on a DOM element

0 commit comments

Comments
 (0)