示例#1
0
test("presence people #4", function (assert) {
    var people = event()
    var doc = Document()
    var room = {
        people: merge([
            [person("j", true), person("k", true)]
            , people
        ])
    }

    presence(room, doc)

    var list = []

    chain(rooms(doc)).
        expand(function (room) {
            return room.people
        }).
        // print("\n").
        into(list)

    send(people, person("j", false))

    send(people, person("k", true))

    assert.equal(list[0].name, "j")
    assert.equal(list[0].eventType, "add")
    assert.equal(list[1].name, "k")
    assert.equal(list[1].eventType, "add")
    assert.equal(list[2].name, "j")
    assert.equal(list[2].eventType, "remove")
    assert.equal(list.length, 3)
    assert.end()
})
示例#2
0
文件: pipe.js 项目: Gozala/event
exports["test pipe multiple streams"] = test(function(assert) {
  var s = event()
  var actual = into(s)

  pipe(merge([[1, 2, 3], [4, 5], [ 6, 7 ]]), s)

  // note that `6` goes through since `end` is also dispatched with a delay.
  assert(actual, [1, 2, 3, 4, 5, 6, 7],
         "parallel pipe works until first end")
})
示例#3
0
var resultSetsOverTime = map(searchQueriesOverTime, function(query) {
  var terms = query.split(/\s+/);

  if (!terms.length || !terms[0]) return SOQ;

  // Search noun matches. Accesses closure variable NOUNS.
  var nounMatches = grepNounMatches(terms, NOUNS);

  return {
    query: query,
    suggestions: nounMatches,
    actions: merge([ searchWithVerb(terms), expandNounMatchesToActions(nounMatches, actionsByType) ])
  };
});
示例#4
0
});

// Get all clicks that originated from an action-completion
var completionTitleClicksOverTime = filter(clicksOverTime, function (event) {
  return (
    event.target.className === 'title' &&
    event.target.parentNode.className === 'action-completion'
  );
});

var clickedTitlesOfCompletionElementsOverTime = map(completionTitleClicksOverTime, function (event) {
  return event.target;
});

var completionTitleElementsOverTime = merge([
  clickedCompletionTitleElementsOverTime,
  clickedTitlesOfCompletionElementsOverTime
]);

var clickedCompletionValuesOverTime = map(completionTitleElementsOverTime, function (element) {
  return element.textContent;
});

// Merge clicked suggested values stream and actionBar values stream.
// Create signal representing query terms entered into action bar,
// also repeats in `searchQuery` are dropped to avoid more work
// down the flow.
var searchQueriesOverTime = dropRepeats(merge([
  clickedCompletionValuesOverTime,
  actionBarValuesOverTime
]));
示例#5
0
test("presence people #5", function (assert) {
    var doc = Document()
    var people = event()
    var room = {
        people: merge([person("a", true), people])
    }
    var time = Timer(Date.now())
    var cleanse = mock("../cleanse", {
        "timers": {
            setTimeout: time.setTimeout
        }
        , "date-now": time.now
    }, require)

    presence(room, doc)
    cleanse(doc)

    var list = []

    chain(rooms(doc)).
        expand(function (room) {
            return room.people
        }).
        // print("\n").
        into(list)

    assert.equal(list[0].eventType, "add")
    assert.equal(list[0].online, true)
    assert.equal(list[0].name, "a")

    time.advance(5000)

    assert.equal(list.length, 2)
    assert.equal(list[1].eventType, "remove")
    assert.equal(list[1].online, false)
    assert.equal(list[1].name, "a")

    send(people, person("a", true, time.now()))

    assert.equal(list.length, 3)
    assert.equal(list[2].eventType, "add")
    assert.equal(list[2].online, true)

    time.advance(3000)

    send(people, person("a", true, time.now()))

    assert.equal(list.length, 3)

    time.advance(2000)

    assert.equal(list.length, 3)

    time.advance(4000)

    assert.equal(list.length, 3)

    time.advance(1000)

    assert.equal(list.length, 4)
    assert.equal(list[3].eventType, "remove")
    assert.equal(list[3].online, false)

    assert.end()
})