Esempio n. 1
0
    /**
     * Create a room
     * (This function should be in RoomService?)
     *
     * @return {[EventStream.<ReceivedMessage>, Bus.<Room>]}
     */
    makeRoom() {
        const roomStreamOne = this.webRTCService.peerOpen().map((key) => {
            this.logger.log("receive a owner key", key);
            // a connection to me is null
            const p = this.playerService.createPlayer(key, null);

            const room = this.roomService.createRoomAsOwner(p);
            this.logger.log("create a room", room);

            return room;
        });

        const messageStream = this.messageService.makeMessageStreamFromPeerConnect();

        const roomBus = new Bacon.Bus();
        roomBus.plug(roomStreamOne);

        Bacon.zipAsArray(roomBus, messageStream).onValue(([room, receivedMessage]) => {
            this.logger.log("make a new room from a message and room");

            const [message, conn] = [receivedMessage.message, receivedMessage.conn];

            if (message.type === "firstHello" && room.isPlayerLocked === false) {
                const newRoom = this.roomService.addNewPlayer(room, message.body.key, conn);
                this.logger.log("new room is created", newRoom);

                this.messageService.sendMessage(conn, this.messages.ownerHello(newRoom));
                roomBus.push(newRoom);
            }
        });

        return [messageStream, roomBus]
    };
Esempio n. 2
0
exports.init = function() {
    var updatePageFromUrl = new Bacon.Bus();
    var initialPageStream = updatePageFromUrl
            .map(U.parseQueryString)
            .map('.n')
            .filter(BU.id);

    window.addEventListener('popstate', function(event) {
        updatePageFromUrl.push();
    }, false);

    function showErrorMessage(msg) {
        $('.errors').html(msg);
    }

    $('body').on('click', '.action', function(e) {
        e.preventDefault();
        var $li = $(this).closest('li');
        $li.hide();

        var stream = BU.jsonRequest('POST', $(this).attr('href'))();

        stream.onError($li, 'show');
        stream.onError(showErrorMessage);

        stream
            .flatMap(getReviewMarkupForNextPhoto)
            .map($)
            .onValue($('ul.thumbnails'), 'append');
    });

    function createPageUpdateStream(initialPageStream) {
        var pageStream = $('.pagination ul li')
                .asEventStream('click')
                .map('.target')
                .map($)
                .map('.data', 'page');

        pageStream
            .map(function(n) { return '?n=' + n; })
            .onValue(function (url) {
                History.pushState(null, '', url);
            });

        var pageUpdateStream = pageStream
                .merge(initialPageStream)
                .map(function(n) { return {'n': n}; })
                .flatMap(BU.jsonRequest('GET', 'partial'));

        pageUpdateStream
            .onValue($('.content'), 'html');

        pageUpdateStream
            .onValue(createPageUpdateStream, initialPageStream);

        return pageUpdateStream;
    }

    createPageUpdateStream(initialPageStream);
};
 cursor.toCursorProperty = function(prop){
   var val;
   this.onValue(function(v){ val = v.get(prop); })();
   if (!val) {
     return null;
   }
   
   var _subBus = new Bacon.Bus();
   _subBus.onValue(function(r){console.log('sub ', prop, r); });
   var subcursor = new CursorProperty(val, _subBus);
 
   var downstream = this.map(function(val){
     return val.get(prop);
   }).onValue(function(val){
     _subBus.push(val);
   });
 
   var upstream = function(sub){
     var root;
     cursor.onValue(function(v){ root = v; });
     var newroot = root.set(prop, sub);
     bus.push(newroot);
   }
   subcursor.push = upstream;
 
   return subcursor;
 };
Esempio n. 4
0
function onMarkerMoved() {
    moveBus.push(marker.getLatLng());
    if (!markerWasMoved) {
        markerWasMoved = true;
        firstMoveBus.push(marker.getLatLng());
        marker.setIcon(getMarkerIcon(true, ''));
    }
}
Esempio n. 5
0
const createPluggable = (log) => () => {
  const stream = new Bacon.Bus()
  return {
    input: stream,
    output: stream
      .doAction(log)
  }
}
Esempio n. 6
0
 const other = createStore('other', () => {
   const stream = new Bacon.Bus()
   return {
     input: stream,
     output: stream
       .map(R.always('test'))
   }
 })
Esempio n. 7
0
 const store = createStore('name', () => {
   const stream = new Bacon.Bus()
   return {
     input: stream,
     output: stream
       .delay(1)
   }
 })
Esempio n. 8
0
    expect: function (streams, ex, assert) {
      var unsub = streams
        .sampledBy(asyncTask)
        .onValue(invert(assert));

      clicks.push(1);
      asyncTask.push(1);
      unsub();
    }
Esempio n. 9
0
  expect: function (streams, ex, assert) {
    var unsub = streams
      .sampledBy(clicks.skip(1))
      .onValue(assert);

    clicks.push(1);
    clicks.push(2);
    unsub();
  }
Esempio n. 10
0
 const store = createStore('name', () => {
   const stream = new Bacon.Bus()
   return {
     input: stream,
     output: stream
       .doAction(logReduce)
       .delay(2)
   }
 })
Esempio n. 11
0
 const store = createStore('name', () => {
   const stream = new Bacon.Bus()
   return {
     input: stream,
     output: stream
       .map(R.always('test'))
       .delay(1)
   }
 })
Esempio n. 12
0
 const store = createStore('name', () => {
   const stream = new Bacon.Bus()
   return {
     input: stream,
     output: stream
       .doAction(logReduce)
       .map(R.always('test'))
   }
 })
Esempio n. 13
0
    expect: function (streams, ex, assert) {
      streams.ships
        .fold(0, function (acc, v) { return acc + v; })
        .onValue(function (v) { return assert(v === 3); });

      shipSensor1.push(zrrkShip);
      shipSensor1.push(zrrkShip);
      shipSensor1.push(zrrkShip);
      shipSensor1.end();
    }
Esempio n. 14
0
    expect: function (streams, ex, assert) {
      streams.ships
        .fold(0, function (acc, v) { return acc + v; })
        .onValue(function (v) { return assert(v === 0); });

      shipSensor2.push(earthianShip);
      shipSensor2.push(purpleShip);
      shipSensor2.push(martianShip);
      shipSensor2.end();
    }
Esempio n. 15
0
  expect: function (streams, ex, assert) {
    streams
      .sampledBy(sector4)
      .onValue(function (v) { return assert(_.isEqual(v, report)); });

    sector1.push(4);
    sector2.push(2);
    sector3.push(1);
    sector4.push(4);
  }
Esempio n. 16
0
    expect: function (streams, ex, assert) {
      var ships = 0;
      streams.shipTally
        .onValue(function (v) {
          ships = v;
        });

      shipSensor.push(zrrkShip);
      shipSensor.push(earthianShip);
      shipSensor.push(zrrkShip);
      assert(ships === 2);
    }
Esempio n. 17
0
export const declutchProperty = (() => {
  const declutchStream = new Bacon.Bus()
  const declutchProperty = declutchStream.toProperty(false)
  initDeclutchProperty(declutchStream)

  return {
    reload: reloadDeclutchProperty(declutchStream),
    get: R.pipe(
      plugDeclutchStream(declutchStream),
      R.always(declutchProperty)
    )
  }
})()
Esempio n. 18
0
  expect: function (stream, exercise, assert) {
    stream.onValue(function (sum) {
      assert(sum === 3);
    });

    c1.push(true);
  }
Esempio n. 19
0
 readChildProcessOutput: function(childProcess) {
   var rl = require('readline');
   var reader = rl.createInterface(childProcess.stdout, childProcess.stdin);
   var bus = new Bacon.Bus();
   reader.on("line", function(data) { bus.push(data); });
   return bus;
 },
Esempio n. 20
0
      expect: function (stream, exercise, assert) {
        stream.onValue(function (report) {
          assert(report !== true);
        });

        c4.push(4000);
      }
Esempio n. 21
0
 this.collection.on('sort', function(collection, e){
   var eventData = {
     collection: this,
     triggeringEvent: e
   };
   shuffleStream.push(new Advisor.Event(advisorName, 'shuffled', eventData));
 });
Esempio n. 22
0
	baconTemplate.map(function (runCounter, mainProd, val) {
		var subProducer = new Bacon.Bus();
		mainProd.plug(subProducer);
		subProducer.onEnd(function() {
			runCounter.push(-1);
		});
		subProducer.onError(function(err) {
			mainProducer.error(err);
			runCounter.push(-1);
			subProducer.end();
		});
		return {
			val: val,
			prodObj: Producer.makeProducer(onDef, subProducer)
		};
	}, runner, mainProducer).onValue(function (fn, name, enter, takeMany, template) {
Esempio n. 23
0
 this.collection.on('sync', function(collection, e){
   var eventData = {
     collection: this,
     triggeringEvent: e
   };
   stream.push(new Advisor.Event(advisorName, 'fetched', eventData));
 });
Esempio n. 24
0
            }).flatMap((receivedMessage) => {
                const owner = this.playerService.createPlayer(ownerKey, receivedMessage.conn);
                const myData = receivedMessage.message.body.players.find((p) => {
                    return p.key === myKey;
                });
                const me = this.playerService.createPlayer(myData.key, null);
                const otherPlayers = receivedMessage.message.body.players.filter((p) => {
                    return p.key !== myKey && p.key !== ownerKey;
                }).map((p) => {
                    const conn = this.webRTCService.connect(p.key);
                    return this.playerService.createPlayer(p.key, conn);
                });
                this.logger.log("other players", otherPlayers);

                const players = Array.prototype.concat([owner], otherPlayers, [me]);
                const room = this.roomService.createRoomAsCommon(me, owner, players);

                roomBus.push(room);
                this.logger.log("room is created", room);

                return Bacon.mergeAll(
                    otherPlayers.map((p) => {
                        return this.messageService.makeMessageStreamFromConnection(p.conn, me.key);
                    })
                );
            });
Esempio n. 25
0
decomposer.onValue(function(task)
{
	var DS = task.DS;
	var objType = task.objType;
	if(! DS.decomposer[objType].isComplete(task) ) //Check if its complete.
	{//No? Ask for the next stuff to get.
		//-Retrieve functional
			//-Same as part B), but with a parameter, the current data.
		/*var newTask = DS.decomposer[objType].extender(task, function (err, result)
		{
			var newType = result.objType;
			var newItem = DS.decomposer[objType].combiner[newType](task.obj, result.obj);
			//Combine and push back into this module.
			//Assume exactly 1 item is created.
			decomposer.push({ obj: newItem, DS: DS, objType: (objType+newType) });
		});*/
		retriever.push(newTask);
	}
	else
	{ //Yes? Actually decomposer.
		console.log("DISMANTLE PHASE, unimplemented");
	/*C) Dismantling things which you have gotten. For each <objType>,
		-There are 3 functionals here:
			-Is complete?
				-<IMPLEMENT isComplete>
			
			-Method for combination of both types of data.
				-<IMPLEMENT combiner<oldType, newType> >  */

	} 
});
Esempio n. 26
0
File: Ui.js Progetto: SirPepe/Pik9
 constructor(presentation){
   this.presentation = presentation;
   this.prepareDom(presentation.$slides);
   this.modeBus = new Bacon.Bus();
   this.mode = this.modeBus.toProperty('none');
   this.setupModes();
 }
Esempio n. 27
0
 intercom.on(busName, function (value) {
     if (value.syncedFromTab !== tabId) {
         delete value.syncedFromTab;
         value.syncedFromOtherTab = true;
         bus.push(value);
     }
 });
Esempio n. 28
0
 this.collection.on('reset', function(collection, e){
   var eventData = {
     collection: this,
     triggeringEvent: e
   };
   resetStream.push(new Advisor.Event(advisorName, 'reset', eventData));
 });
Esempio n. 29
0
const dispatcher = () => {
    const bus = new Bacon.Bus();
    return ({
        stream: () => bus,
        add: () => bus.push(1),
        sub: () => bus.push(-1)
    });
};
Esempio n. 30
0
		var pollRetFunction = function(objs) //obj = [{action: function(cb), objType: string}] //cb(err, result)
		{
			assert(_.every(objs, function(obj){ return _.isFunction(obj.action) && _.isString(obj.objType);  }, "Incorrect typing on objs"));
			//Insert into objects to retriever.
			//console.log("Retrieving ", objs);
			objs = _.map(objs, function(obj) { obj.DS = val; return obj }); //attach the DS.
			retriever.plug(Bacon.fromArray(objs));
		};