Skip to content

Commit

Permalink
fix(lsstate): fix fromPlain method
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricenclos committed Dec 4, 2018
1 parent cfa9121 commit facb457
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/CrdtImpl/LogootSplit/LSState.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { LogootSOperation, LogootSRopes } from "mute-structs";
import { SafeAny } from "safe-any";
import { State, StateJSON } from "../../core";
import { generateId } from "../../misc";
import { LSRichOperation } from "./LSRichOperation";
import { LogootSOperation, LogootSRopes } from 'mute-structs'
import { SafeAny } from 'safe-any'
import { State, StateJSON } from '../../core'
import { generateId } from '../../misc'
import { LSRichOperation } from './LSRichOperation'

export class LSState extends State<LogootSRopes, LogootSOperation> {

static emptyState (): LSState {
static emptyState(): LSState {
const id = generateId()
return new LSState(id, new LogootSRopes(id), [], new Map(), 0)
}

static fromPlain (o: SafeAny<StateJSON<LogootSRopes, LogootSOperation>>): LSState | null {
if (o !== null && typeof o === 'object' && o.richOps instanceof Array) {
static fromPlain(o: SafeAny<StateJSON<LogootSRopes, LogootSOperation>>): LSState | null {
if (o !== null && typeof o === 'object' && o.remoteOperations instanceof Array) {
// If one operation is null -> error
const lsRichOperations = o.richOps.map((rich) => {
return LSRichOperation.fromPlain(rich)
const lsRichOperations = o.remoteOperations.map((richOp) => {
return LSRichOperation.fromPlain(richOp)
}) as LSRichOperation[]
const nbOperationNull = lsRichOperations.filter((r) => r === null).length
if (nbOperationNull > 0) {
Expand Down Expand Up @@ -68,4 +67,4 @@ export class LSState extends State<LogootSRopes, LogootSOperation> {
}
return null
}
}
}

0 comments on commit facb457

Please sign in to comment.