Skip to content

Commit

Permalink
add optimizations tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiamanzati committed Jul 18, 2017
1 parent ce09e26 commit 111d286
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/optimizations.ts
@@ -0,0 +1,36 @@
import { getSnapshot, applySnapshot, unprotect, types } from "../src"
import { test } from "ava"

test("it should avoid processing patch if is exactly the current one in applySnapshot", t => {
let called = false
const Model = types.model({
a: types.number,
b: types.string
})

const store = Model.create({ a: 1, b: "hello" })
called = false

const snapshot = getSnapshot(store)
applySnapshot(store, snapshot)
t.is(getSnapshot(store), snapshot) // no new snapshot emitted
})

test("it should avoid processing patch if is exactly the current one in reconcile", t => {
const Model = types.model({
a: types.number,
b: types.string
})

const RootModel = types.model({
a: Model
})

const store = RootModel.create({ a: { a: 1, b: "hello" } })
unprotect(store)

const snapshot = getSnapshot(store)
store.a = snapshot.a
t.is(getSnapshot(store.a), snapshot.a)
t.deepEqual(getSnapshot(store), snapshot)
})

0 comments on commit 111d286

Please sign in to comment.