Skip to content

Commit

Permalink
Merge pull request #3 from justingreenberg/feature/es-class-props
Browse files Browse the repository at this point in the history
(feature/core) use es class instance fields
  • Loading branch information
mbasso authored Jul 8, 2016
2 parents 84847b5 + deac3fc commit 729c1c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
8 changes: 5 additions & 3 deletions src/History.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export default class {
export default class History {

items = [];
limit = 200;

constructor(limit) {
this.setLimit(limit);
this.items = [];
}

setLimit(limit) {
this.limit = Number(limit) > 0 ? Number(limit) : 200;
this.limit = Number(limit) > 0 ? Number(limit) : this.limit;
}

add(payload) {
Expand Down
9 changes: 3 additions & 6 deletions src/Mediator.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
export default class {
export default class Mediator {

constructor() {
this.subscribers = [];
this.publish = ::this.publish;
}
subscribers = [];

subscribe(subscriber) {
if (this.subscribers.indexOf(subscriber) === -1) {
Expand All @@ -18,7 +15,7 @@ export default class {
}
}

publish(channel, param) {
publish = (channel, param) => {
this.subscribers.forEach((subscriber) => {
if (!subscriber) {
this.unsubscribe(subscriber);
Expand Down
16 changes: 8 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import Mediator from './Mediator';
import History from './History';

export default class {
export default class Refraction {

middlewares = [];

mediator = new Mediator();
history = new History();

constructor(middlewares = []) {
this.mediator = new Mediator();
this.history = new History();
this.middlewares = [];
this.addToHistory = ::this.addToHistory;
this.applyMiddleware = ::this.applyMiddleware;
this.applyMiddleware(...middlewares, this.addToHistory);
}

applyMiddleware(...middlewares) {
applyMiddleware = (...middlewares) => {
if (middlewares.length === 1) {
this.middlewares.push(middlewares[0]);
} else if (middlewares.length > 0) {
middlewares.forEach((middleware) => this.applyMiddleware(middleware));
}
}

addToHistory(channel, param) {
addToHistory = (channel, param) => {
this.history.add({
channel,
time: (performance && performance.now) ? performance.now() : null,
Expand Down

0 comments on commit 729c1c9

Please sign in to comment.