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