Skip to content

Commit

Permalink
[renamed] Scheduler to Runtime
Browse files Browse the repository at this point in the history
Summary: As discussed in https://groups.google.com/forum/#!msg/material-motion/FNULoSyqEOo/Of3wOnR3BwAJ

Test Plan: The current test suite passes.

Reviewers: featherless, markwei, O2 Material Motion, shyndman, O3 Material Motion JavaScript platform reviewers

Reviewed By: featherless, markwei, O2 Material Motion, shyndman, O3 Material Motion JavaScript platform reviewers

Subscribers: markwei, shyndman

Tags: #material_motion

Differential Revision: http://codereview.cc/D1824
  • Loading branch information
appsforartists committed Nov 1, 2016
1 parent b19d922 commit b54d8cc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import {
type ActivityListener = (kwargs: { isActive: boolean }) => any;

/**
* The Scheduler is responsible for fulfilling Plans by delegating them to the
* A runtime is responsible for fulfilling Plans by delegating them to the
* correct Performer.
*/
export default class Scheduler {
export default class Runtime {
_performerMapSelector = makeCompoundKeySelector('PerformerType', 'target');
_performerMap: Map<any, Performing> = new Map();
_activityListeners: Set<ActivityListener> = new Set();
Expand All @@ -45,23 +45,23 @@ export default class Scheduler {
);

/**
* If any of this scheduler's performers aren't at rest, this will be true.
* If any of this runtime's performers aren't at rest, this will be true.
*/
get isActive(): boolean {
return this._isActive;
}

/**
* The Scheduler will ensure the given plan is immediately applied to the
* given target.
* The runtime ensures the given plan is immediately applied to the given
* target.
*/
addPlan({ plan, target }: PlanAndTarget): void {
if (!plan) {
throw new Error(`Scheduler.addPlan requires a plan`);
throw new Error(`runtime.addPlan requires a plan`);
}

if (!target) {
throw new Error(`Scheduler.addPlan requires a target`);
throw new Error(`runtime.addPlan requires a target`);
}

const isActiveTokenGenerator = this._isActiveTokenGenerator;
Expand Down Expand Up @@ -102,15 +102,15 @@ export default class Scheduler {
// - It's easy to attach to existing libraries, e.g. RxJS's fromEventPattern.

/**
* Any function passed here will be called every time scheduler.isActive
* Any function passed here will be called every time runtime.isActive
* changes.
*/
addActivityListener({ listener }:{ listener: ActivityListener }) {
this._activityListeners.add(listener);
}

/**
* Stops notifying the given listener of changes to scheduler.isActive.
* Stops notifying the given listener of changes to runtime.isActive.
*/
removeActivityListener({ listener }:{ listener: ActivityListener }) {
this._activityListeners.delete(listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ import {
stub,
} from 'sinon';

import Scheduler from '../Scheduler';
import Runtime from '../Runtime';

// chai really doesn't like being imported as an ES2015 module; will be fixed in v4
require('chai').use(
require('sinon-chai')
);

describe('Scheduler.addPlan',
describe('runtime.addPlan',
() => {
let scheduler;
let runtime;
let addPlanSpy;
let PerformerSpy;
let planWithSpies;
let target = {};

beforeEach(
() => {
scheduler = new Scheduler();
runtime = new Runtime();

addPlanSpy = stub();

Expand All @@ -63,7 +63,7 @@ describe('Scheduler.addPlan',
() => {
expect(
() => {
scheduler.addPlan();
runtime.addPlan();
}
).to.throw();
}
Expand All @@ -73,7 +73,7 @@ describe('Scheduler.addPlan',
() => {
expect(
() => {
scheduler.addPlan({ plan: planWithSpies });
runtime.addPlan({ plan: planWithSpies });
}
).to.throw(`requires a target`);
}
Expand All @@ -83,24 +83,24 @@ describe('Scheduler.addPlan',
() => {
expect(
() => {
scheduler.addPlan({ target });
runtime.addPlan({ target });
}
).to.throw(`requires a plan`);
}
);

it(`should create a performer from plan._PerformerType`,
() => {
scheduler.addPlan({ plan: planWithSpies, target });
runtime.addPlan({ plan: planWithSpies, target });

expect(planWithSpies._PerformerType).to.be.calledWithNew;
}
);

it(`should recycle performers for the same plan and target`,
() => {
scheduler.addPlan({ plan: planWithSpies, target });
scheduler.addPlan({ plan: planWithSpies, target });
runtime.addPlan({ plan: planWithSpies, target });
runtime.addPlan({ plan: planWithSpies, target });
expect(PerformerSpy).to.have.been.calledOnce;
}
);
Expand All @@ -111,24 +111,24 @@ describe('Scheduler.addPlan',
_PerformerType: PerformerSpy,
};

scheduler.addPlan({ plan: planWithSpies, target });
scheduler.addPlan({ plan: otherPlanSamePerformerType, target });
runtime.addPlan({ plan: planWithSpies, target });
runtime.addPlan({ plan: otherPlanSamePerformerType, target });
expect(PerformerSpy).to.have.been.calledOnce;
}
);

it(`should create new performers for each target`,
() => {
scheduler.addPlan({ plan: planWithSpies, target });
scheduler.addPlan({ plan: planWithSpies, target: {} });
runtime.addPlan({ plan: planWithSpies, target });
runtime.addPlan({ plan: planWithSpies, target: {} });
expect(PerformerSpy).to.have.been.calledTwice;
}
);

it(`should call performer.addPlan for each plan`,
() => {
scheduler.addPlan({ plan: planWithSpies, target });
scheduler.addPlan({ plan: planWithSpies, target });
runtime.addPlan({ plan: planWithSpies, target });
runtime.addPlan({ plan: planWithSpies, target });
expect(addPlanSpy).to.have.been.calledTwice;
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
spy,
} from 'sinon';

import Scheduler from '../Scheduler';
import Runtime from '../Runtime';

class ActivityTestingPerformer {
tokens = [];
Expand Down Expand Up @@ -57,48 +57,48 @@ const endActivityPlan = {
_PerformerType: ActivityTestingPerformer,
};

describe('Scheduler.addPlan',
describe('runtime.addPlan',
() => {
let scheduler;
let runtime;
let target = {};

beforeEach(
() => {
scheduler = new Scheduler();
runtime = new Runtime();
}
);

it(`should start at rest`,
() => {
expect(scheduler.isActive).to.be.false;
expect(runtime.isActive).to.be.false;
}
);

it(`should become active when a continuous performer is added`,
() => {
scheduler.addPlan({ plan: startActivityPlan, target });
expect(scheduler.isActive).to.be.true;
runtime.addPlan({ plan: startActivityPlan, target });
expect(runtime.isActive).to.be.true;
}
);

it(`should be active when some continuous performers have not completed`,
() => {
scheduler.addPlan({ plan: startActivityPlan, target });
scheduler.addPlan({ plan: startActivityPlan, target });
scheduler.addPlan({ plan: endActivityPlan, target });
runtime.addPlan({ plan: startActivityPlan, target });
runtime.addPlan({ plan: startActivityPlan, target });
runtime.addPlan({ plan: endActivityPlan, target });

expect(scheduler.isActive).to.be.true;
expect(runtime.isActive).to.be.true;
}
);

it(`should be at rest when all continuous performers have completed`,
() => {
scheduler.addPlan({ plan: startActivityPlan, target });
scheduler.addPlan({ plan: startActivityPlan, target });
scheduler.addPlan({ plan: endActivityPlan, target });
scheduler.addPlan({ plan: endActivityPlan, target });
runtime.addPlan({ plan: startActivityPlan, target });
runtime.addPlan({ plan: startActivityPlan, target });
runtime.addPlan({ plan: endActivityPlan, target });
runtime.addPlan({ plan: endActivityPlan, target });

expect(scheduler.isActive).to.be.false;
expect(runtime.isActive).to.be.false;
}
);

Expand All @@ -107,10 +107,10 @@ describe('Scheduler.addPlan',
const spy1 = spy();
const spy2 = spy();

scheduler.addActivityListener({ listener: spy1 });
scheduler.addActivityListener({ listener: spy2 });
runtime.addActivityListener({ listener: spy1 });
runtime.addActivityListener({ listener: spy2 });

scheduler.addPlan({ plan: startActivityPlan, target });
runtime.addPlan({ plan: startActivityPlan, target });

expect(spy1.lastCall.args[0].isActive).to.be.true;
expect(spy2.lastCall.args[0].isActive).to.be.true;
Expand All @@ -122,14 +122,14 @@ describe('Scheduler.addPlan',
const spy1 = spy();
const spy2 = spy();

scheduler.addActivityListener({ listener: spy1 });
scheduler.addActivityListener({ listener: spy2 });
runtime.addActivityListener({ listener: spy1 });
runtime.addActivityListener({ listener: spy2 });

scheduler.addPlan({ plan: startActivityPlan, target });
runtime.addPlan({ plan: startActivityPlan, target });

scheduler.removeActivityListener({ listener: spy2 });
runtime.removeActivityListener({ listener: spy2 });

scheduler.addPlan({ plan: endActivityPlan, target });
runtime.addPlan({ plan: endActivityPlan, target });

expect(spy1.lastCall.args[0].isActive).to.be.false;
expect(spy2.lastCall.args[0].isActive).to.be.true;
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
*/

export * from './types';
export * from './Scheduler';
export { default as Scheduler } from './Scheduler';
export * from './Runtime';
export { default as Runtime } from './Runtime';

0 comments on commit b54d8cc

Please sign in to comment.