added flow support for Struct.js
This commit is contained in:
		
							parent
							
								
									da2762edf5
								
							
						
					
					
						commit
						e9c40f9a83
					
				@ -17,7 +17,12 @@ type Operation = Struct
 | 
				
			|||||||
type Insertion = {
 | 
					type Insertion = {
 | 
				
			||||||
  id: Id,
 | 
					  id: Id,
 | 
				
			||||||
  left: Id,
 | 
					  left: Id,
 | 
				
			||||||
 | 
					  origin: Id,
 | 
				
			||||||
  right: Id,
 | 
					  right: Id,
 | 
				
			||||||
 | 
					  parent: Id,
 | 
				
			||||||
 | 
					  parentSub: ?Id,
 | 
				
			||||||
 | 
					  opContent: ?Id,
 | 
				
			||||||
 | 
					  content: ?any,
 | 
				
			||||||
  struct: 'Insert'
 | 
					  struct: 'Insert'
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,10 +1,10 @@
 | 
				
			|||||||
/* @flow */
 | 
					/* @flow */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type YGlobal = {
 | 
					type YGlobal = {
 | 
				
			||||||
	utils: Object;
 | 
						utils: Object,
 | 
				
			||||||
	Struct: Object;
 | 
						Struct: any,
 | 
				
			||||||
	AbstractDatabase: any;
 | 
						AbstractDatabase: any,
 | 
				
			||||||
	AbstractConnector: any;
 | 
						AbstractConnector: any
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type YConfig = {
 | 
					type YConfig = {
 | 
				
			||||||
 | 
				
			|||||||
@ -11,7 +11,7 @@ module.exports = function (Y/* :YGlobal */) {
 | 
				
			|||||||
    userEventListeners: Array<Function>;
 | 
					    userEventListeners: Array<Function>;
 | 
				
			||||||
    whenSyncedListeners: Array<Function>;
 | 
					    whenSyncedListeners: Array<Function>;
 | 
				
			||||||
    currentSyncTarget: ?UserId;
 | 
					    currentSyncTarget: ?UserId;
 | 
				
			||||||
    syncingClients: Array<any>;
 | 
					    syncingClients: Array<UserId>;
 | 
				
			||||||
    forwardToSyncingClients: boolean;
 | 
					    forwardToSyncingClients: boolean;
 | 
				
			||||||
    debug: boolean;
 | 
					    debug: boolean;
 | 
				
			||||||
    broadcastedHB: boolean;
 | 
					    broadcastedHB: boolean;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					/* @flow */
 | 
				
			||||||
'use strict'
 | 
					'use strict'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@ -18,7 +19,7 @@
 | 
				
			|||||||
 * requiredOps
 | 
					 * requiredOps
 | 
				
			||||||
     - Operations that are required to execute this operation.
 | 
					     - Operations that are required to execute this operation.
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
module.exports = function (Y) {
 | 
					module.exports = function (Y/* :YGlobal */) {
 | 
				
			||||||
  var Struct = {
 | 
					  var Struct = {
 | 
				
			||||||
    /* This is the only operation that is actually not a structure, because
 | 
					    /* This is the only operation that is actually not a structure, because
 | 
				
			||||||
    it is not stored in the OS. This is why it _does not_ have an id
 | 
					    it is not stored in the OS. This is why it _does not_ have an id
 | 
				
			||||||
@ -49,10 +50,10 @@ module.exports = function (Y) {
 | 
				
			|||||||
          parentSub: string (optional), // child of Map type
 | 
					          parentSub: string (optional), // child of Map type
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      */
 | 
					      */
 | 
				
			||||||
      encode: function (op) {
 | 
					      encode: function (op/* :Insertion */) /* :Insertion */ {
 | 
				
			||||||
        // TODO: you could not send the "left" property, then you also have to
 | 
					        // TODO: you could not send the "left" property, then you also have to
 | 
				
			||||||
        // "op.left = null" in $execute or $decode
 | 
					        // "op.left = null" in $execute or $decode
 | 
				
			||||||
        var e = {
 | 
					        var e/* :any */ = {
 | 
				
			||||||
          id: op.id,
 | 
					          id: op.id,
 | 
				
			||||||
          left: op.left,
 | 
					          left: op.left,
 | 
				
			||||||
          right: op.right,
 | 
					          right: op.right,
 | 
				
			||||||
@ -160,7 +161,11 @@ module.exports = function (Y) {
 | 
				
			|||||||
              break
 | 
					              break
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            i++
 | 
					            i++
 | 
				
			||||||
            o = o.right ? yield* this.getOperation(o.right) : null
 | 
					            if (o.right != null) {
 | 
				
			||||||
 | 
					              o = yield* this.getOperation(o.right)
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					              o = null
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
            break
 | 
					            break
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
@ -169,7 +174,9 @@ module.exports = function (Y) {
 | 
				
			|||||||
        // reconnect..
 | 
					        // reconnect..
 | 
				
			||||||
        var left = null
 | 
					        var left = null
 | 
				
			||||||
        var right = null
 | 
					        var right = null
 | 
				
			||||||
        parent = parent || (yield* this.getOperation(op.parent))
 | 
					        if (parent == null) {
 | 
				
			||||||
 | 
					          parent = yield* this.getOperation(op.parent)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // reconnect left and set right of op
 | 
					        // reconnect left and set right of op
 | 
				
			||||||
        if (op.left != null) {
 | 
					        if (op.left != null) {
 | 
				
			||||||
@ -267,7 +274,7 @@ module.exports = function (Y) {
 | 
				
			|||||||
            pos--
 | 
					            pos--
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
          if (pos >= 0 && o.right != null) {
 | 
					          if (pos >= 0 && o.right != null) {
 | 
				
			||||||
            o = (yield* this.getOperation(o.right))
 | 
					            o = yield* this.getOperation(o.right)
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
            break
 | 
					            break
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
@ -315,19 +322,13 @@ module.exports = function (Y) {
 | 
				
			|||||||
        var oid = op.map[name]
 | 
					        var oid = op.map[name]
 | 
				
			||||||
        if (oid != null) {
 | 
					        if (oid != null) {
 | 
				
			||||||
          var res = yield* this.getOperation(oid)
 | 
					          var res = yield* this.getOperation(oid)
 | 
				
			||||||
          return (res == null || res.deleted) ? void 0 : (res.opContent == null
 | 
					          if (res == null || res.deleted) {
 | 
				
			||||||
            ? res.content : yield* this.getType(res.opContent))
 | 
					            return void 0
 | 
				
			||||||
        }
 | 
					          } else if (res.opContent == null) {
 | 
				
			||||||
      },
 | 
					            return res.content
 | 
				
			||||||
      /*
 | 
					          } else {
 | 
				
			||||||
        Delete a property by name
 | 
					            return yield* this.getType(res.opContent)
 | 
				
			||||||
      */
 | 
					          }
 | 
				
			||||||
      delete: function * (op, name) {
 | 
					 | 
				
			||||||
        var v = op.map[name] || null
 | 
					 | 
				
			||||||
        if (v != null) {
 | 
					 | 
				
			||||||
          yield* Struct.Delete.create.call(this, {
 | 
					 | 
				
			||||||
            target: v
 | 
					 | 
				
			||||||
          })
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user