Skip to content

Commit

Permalink
import only the necessities, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
treywood committed Nov 2, 2016
1 parent 94cc57b commit 8435ed1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ You can import RxJs from the `rxjs` module:
import Rx from 'rxjs/Rx';
```

Note that - for the sake of your build sizes - only the operators and observables necessary to implement the utilities below are imported within the addon. This means that in order to use the majority of RxJs' operators, you will need to import them (or everything from ```rxjs/Rx```) in your own app.

More on that [here](https://github.com/ReactiveX/rxjs#installation-and-usage).

## Utilities
Expand Down
10 changes: 6 additions & 4 deletions addon/mixins/observable.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Ember from 'ember';
import Rx from 'rxjs/Rx';
import { Subject } from 'rxjs/Subject';
import { combineLatest } from 'rxjs/observable/combineLatest';
import 'rxjs/add/operator/startWith';

function action(actionName) {
let existing = this.actions[actionName] || function() {};
let s = this._actionSubjects[actionName];
if (!s) {
s = (this._actionSubjects[actionName] = new Rx.Subject());
s = (this._actionSubjects[actionName] = new Subject());
this.actions[actionName] = function() {
try {
existing.apply(this, arguments);
Expand All @@ -21,7 +23,7 @@ function action(actionName) {
function property(propertyName) {
let s = this._propSubjects[propertyName];
if (!s) {
s = (this._propSubjects[propertyName] = new Rx.Subject());
s = (this._propSubjects[propertyName] = new Subject());
this.addObserver(propertyName, () => {
try {
s.next(this.get(propertyName));
Expand All @@ -34,7 +36,7 @@ function property(propertyName) {
}

function properties(...props) {
return Rx.Observable.combineLatest(props.map(p => this.observable.property(p)));
return combineLatest(props.map(p => this.observable.property(p)));
}

export default Ember.Mixin.create({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-cli-rxjs",
"version": "0.2.4",
"version": "1.0.0",
"description": "RxJS utilities for Ember.",
"directories": {
"doc": "doc",
Expand Down
6 changes: 4 additions & 2 deletions tests/dummy/app/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Ember from 'ember';
import Rx from 'rxjs/Rx';
import { interval } from 'rxjs/observable/interval';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/combineLatest';

export default Ember.Controller.extend({

Expand All @@ -9,7 +11,7 @@ export default Ember.Controller.extend({
this.set('multiplier', 1);

this.observable.property('multiplier')
.combineLatest(Rx.Observable.interval(1000))
.combineLatest(interval(1000))
.map(([m, i]) => m * i)
.subscribe(x => this.set('number', x));
}
Expand Down
8 changes: 6 additions & 2 deletions tests/dummy/app/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Ember from 'ember';
import Rx from 'rxjs/Rx';
import { interval } from 'rxjs/observable/interval';
import 'rxjs/add/operator/scan';
import 'rxjs/add/operator/startWith';
import 'rxjs/add/operator/combineLatest';
import 'rxjs/add/operator/map';

export default Ember.Route.extend({

Expand All @@ -10,7 +14,7 @@ export default Ember.Route.extend({
return this.observable.action('reverse')
.scan(op => op === pos ? neg : pos, pos)
.startWith(pos)
.combineLatest(Rx.Observable.interval(1000))
.combineLatest(interval(1000))
.map(([op, n]) => op(n));
},

Expand Down

0 comments on commit 8435ed1

Please sign in to comment.