added flow support for everything except tests
This commit is contained in:
parent
0ebfae6997
commit
eff6fb1cc5
@ -16,9 +16,9 @@ type Operation = Struct
|
||||
|
||||
type Insertion = {
|
||||
id: Id,
|
||||
left: Id,
|
||||
origin: Id,
|
||||
right: Id,
|
||||
left: ?Id,
|
||||
origin: ?Id,
|
||||
right: ?Id,
|
||||
parent: Id,
|
||||
parentSub: ?Id,
|
||||
opContent: ?Id,
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* @flow */
|
||||
'use strict'
|
||||
|
||||
module.exports = function (Y/* :YGlobal */) {
|
||||
module.exports = function (Y/* :any */) {
|
||||
class AbstractConnector {
|
||||
/* ::
|
||||
y: YConfig;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* @flow */
|
||||
'use strict'
|
||||
|
||||
module.exports = function (Y /* :YGlobal */) {
|
||||
module.exports = function (Y /* :any */) {
|
||||
/*
|
||||
Partial definition of an OperationStore.
|
||||
TODO: name it Database, operation store only holds operations.
|
||||
|
@ -19,7 +19,7 @@
|
||||
* requiredOps
|
||||
- Operations that are required to execute this operation.
|
||||
*/
|
||||
module.exports = function (Y/* :YGlobal */) {
|
||||
module.exports = function (Y/* :any */) {
|
||||
var Struct = {
|
||||
/* 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
|
||||
|
@ -74,7 +74,7 @@
|
||||
- this is called only by `getOperations(startSS)`. It makes an operation
|
||||
applyable on a given SS.
|
||||
*/
|
||||
module.exports = function (Y/* :YGlobal */) {
|
||||
module.exports = function (Y/* :any */) {
|
||||
class TransactionInterface {
|
||||
/* ::
|
||||
store: Y.AbstractDatabase;
|
||||
|
@ -1,7 +1,16 @@
|
||||
/* @flow */
|
||||
'use strict'
|
||||
|
||||
module.exports = function (Y) {
|
||||
module.exports = function (Y /* :any */) {
|
||||
class YMap {
|
||||
/* ::
|
||||
_model: Id;
|
||||
os: Y.AbstractDatabase;
|
||||
map: Object;
|
||||
contents: any;
|
||||
opContents: Object;
|
||||
eventHandler: Function;
|
||||
*/
|
||||
constructor (os, model, contents, opContents) {
|
||||
this._model = model.id
|
||||
this.os = os
|
||||
@ -22,7 +31,8 @@ module.exports = function (Y) {
|
||||
oldValue = () => {// eslint-disable-line
|
||||
return new Promise((resolve) => {
|
||||
this.os.requestTransaction(function *() {// eslint-disable-line
|
||||
resolve(yield* this.getType(prevType))
|
||||
var type = yield* this.getType(prevType)
|
||||
resolve(type)
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -48,15 +58,20 @@ module.exports = function (Y) {
|
||||
}
|
||||
}
|
||||
this.map[key] = op.id
|
||||
var insertEvent = {
|
||||
name: key,
|
||||
object: this
|
||||
}
|
||||
var insertEvent
|
||||
if (oldValue === undefined) {
|
||||
insertEvent.type = 'add'
|
||||
insertEvent = {
|
||||
name: key,
|
||||
object: this,
|
||||
type: 'add'
|
||||
}
|
||||
} else {
|
||||
insertEvent.type = 'update'
|
||||
insertEvent.oldValue = oldValue
|
||||
insertEvent = {
|
||||
name: key,
|
||||
object: this,
|
||||
oldValue: oldValue,
|
||||
type: 'update'
|
||||
}
|
||||
}
|
||||
userEvents.push(insertEvent)
|
||||
}
|
||||
@ -92,7 +107,8 @@ module.exports = function (Y) {
|
||||
return new Promise((resolve) => {
|
||||
var oid = this.opContents[key]
|
||||
this.os.requestTransaction(function *() {
|
||||
resolve(yield* this.getType(oid))
|
||||
var type = yield* this.getType(oid)
|
||||
resolve(type)
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -133,7 +149,7 @@ module.exports = function (Y) {
|
||||
// if not, apply immediately on this type an call event
|
||||
|
||||
var right = this.map[key] || null
|
||||
var insert = {
|
||||
var insert /* :any */ = {
|
||||
left: null,
|
||||
right: right,
|
||||
origin: null,
|
||||
@ -236,7 +252,9 @@ module.exports = function (Y) {
|
||||
for (var e in events) {
|
||||
var event = events[e]
|
||||
if (event.name === path[0]) {
|
||||
deleteChildObservers()
|
||||
if (deleteChildObservers != null) {
|
||||
deleteChildObservers()
|
||||
}
|
||||
if (event.type === 'add' || event.type === 'update') {
|
||||
resetObserverPath()
|
||||
}
|
||||
@ -248,8 +266,10 @@ module.exports = function (Y) {
|
||||
return resetObserverPath().then(
|
||||
// this promise contains a function that deletes all the child observers
|
||||
// and how to unobserve the observe from this object
|
||||
Promise.resolve(function () {
|
||||
deleteChildObservers()
|
||||
new Promise.resolve(function () { // eslint-disable-line
|
||||
if (deleteChildObservers != null) {
|
||||
deleteChildObservers()
|
||||
}
|
||||
self.unobserve(observer)
|
||||
})
|
||||
)
|
||||
|
@ -23,7 +23,7 @@
|
||||
database request to finish). EventHandler will help you to make your type
|
||||
synchronous.
|
||||
*/
|
||||
module.exports = function (Y /* : YGlobal*/) {
|
||||
module.exports = function (Y /* : any*/) {
|
||||
Y.utils = {}
|
||||
|
||||
class EventHandler {
|
||||
|
37
src/y.js
37
src/y.js
@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
'use strict'
|
||||
|
||||
require('./Connector.js')(Y)
|
||||
@ -55,7 +56,37 @@ function requestModules (modules) {
|
||||
|
||||
require('./Types/Map.js')(Y)
|
||||
|
||||
function Y (opts) {
|
||||
/* ::
|
||||
type MemoryOptions = {
|
||||
name: 'memory'
|
||||
}
|
||||
type IndexedDBOptions = {
|
||||
name: 'indexeddb',
|
||||
namespace: string
|
||||
}
|
||||
type DbOptions = MemoryOptions | IndexedDBOptions
|
||||
|
||||
type WebRTCOptions = {
|
||||
name: 'webrtc',
|
||||
room: string
|
||||
}
|
||||
type WebsocketsClientOptions = {
|
||||
name: 'websockets-client',
|
||||
room: string
|
||||
}
|
||||
type ConnectionOptions = WebRTCOptions | WebsocketsClientOptions
|
||||
|
||||
type TypesOptions = Array<'array'|'map'|'text'>
|
||||
|
||||
type YOptions = {
|
||||
connector: ConnectionOptions,
|
||||
db: DbOptions,
|
||||
types: TypesOptions,
|
||||
sourceDir: string
|
||||
}
|
||||
*/
|
||||
|
||||
function Y (opts/* :YOptions */) /* :Promise<YConfig> */ {
|
||||
opts.types = opts.types != null ? opts.types : []
|
||||
var modules = [opts.db.name, opts.connector.name].concat(opts.types)
|
||||
Y.sourceDir = opts.sourceDir
|
||||
@ -71,6 +102,10 @@ function Y (opts) {
|
||||
}
|
||||
|
||||
class YConfig {
|
||||
/* ::
|
||||
db: Y.AbstractDatabase;
|
||||
connector: Y.AbstractConnector;
|
||||
*/
|
||||
constructor (opts, callback) {
|
||||
this.db = new Y[opts.db.name](this, opts.db)
|
||||
this.connector = new Y[opts.connector.name](this, opts.connector)
|
||||
|
Loading…
x
Reference in New Issue
Block a user