Skip to content

Commit

Permalink
Scope all selectors to prevent messing with user apps, closes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
Widdershin committed Aug 31, 2015
1 parent 3e24e60 commit c2f70dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function model (click$) {
}

function intent (DOM) {
return DOM.select('.increment').events('click);
return DOM.select('.increment').events('click');
}

function main ({DOM}) {
Expand Down
19 changes: 14 additions & 5 deletions src/time-travel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,31 @@ function calculateTimestamp (mouseX) {
return mouseX / document.documentElement.clientWidth * 10000;
}

function logStreams (DOM, streams) {
function scopedDOM (DOM, scope) {
return {
select (selector) {
return DOM.select(`${scope} ${selector}`);
}
};
}

function logStreams (DOM, streams, name = '.time-travel') {
const timeTravel = {};
const timeTravelDOM = scopedDOM(DOM, name);

const mousePosition$ = DOM.select('.stream').events('mousemove')
const mousePosition$ = timeTravelDOM.select('.stream').events('mousemove')
.map(getMousePosition)
.startWith({x: 0, y: 0});

const click$ = DOM.select('.stream').events('mousedown');
const click$ = timeTravelDOM.select('.stream').events('mousedown');
const release$ = Rx.Observable.fromEvent(document.body, 'mouseup');

const dragging$ = Rx.Observable.merge(
click$.map(_ => true),
release$.map(_ => false)
).startWith(false);

const playingClick$ = DOM.select('.pause').events('click')
const playingClick$ = timeTravelDOM.select('.pause').events('click')
.scan((previous, _) => !previous, true)
.startWith(true);

Expand Down Expand Up @@ -124,7 +133,7 @@ function logStreams (DOM, streams) {
return {
DOM: Rx.Observable.combineLatest(time$, playing$, ...loggedStreams,
(currentTime, playing, ...streamValues) => {
return h('.time-travel', [
return h(name, [
stylesheet(),
h('button.pause', playing ? 'Pause' : 'Play'),
renderStreams(currentTime, ...streamValues)
Expand Down

0 comments on commit c2f70dc

Please sign in to comment.