mirror of https://gitee.com/cf-fz/WebCAD.git
parent
0e42c14ebb
commit
79655caedb
@ -0,0 +1,33 @@
|
||||
import * as mst from 'mobx-state-tree';
|
||||
import { EntityData } from '../../src/DatabaseServices/EntityData';
|
||||
import * as THREE from 'three';
|
||||
test("Entity", () =>
|
||||
{
|
||||
let d = EntityData.create({ size: [0, 1, 2] })
|
||||
|
||||
console.log(mst.getSnapshot(d));
|
||||
|
||||
console.log(d.getSize());
|
||||
d.setSize(1, 1, 1000);
|
||||
console.log(d.getSize());
|
||||
|
||||
|
||||
expect(d.getSize().x).toBe(1);
|
||||
})
|
||||
|
||||
test("not late", () =>
|
||||
{
|
||||
let d = EntityData.create({ size: [0, 1, 2] })
|
||||
|
||||
console.log(mst.getSnapshot(d));
|
||||
|
||||
console.log(d.getSize());
|
||||
d.setSize(1, 1, 1000);
|
||||
console.log(d.getSize());
|
||||
|
||||
expect(d.getSize().x).toBe(1);
|
||||
expect(d.getSize().y).toBe(1);
|
||||
expect(d.getSize().z).toBe(1000);
|
||||
|
||||
console.log(typeof d.getSize());
|
||||
})
|
@ -0,0 +1,68 @@
|
||||
import * as mst from 'mobx-state-tree';
|
||||
import * as _ from "lodash";
|
||||
import * as THREE from "three";
|
||||
const Todo = mst.types.model("Todo",
|
||||
{
|
||||
title: mst.types.maybe(mst.types.string),
|
||||
done: false
|
||||
},
|
||||
{
|
||||
toggle()
|
||||
{
|
||||
this.done = !this.done
|
||||
},
|
||||
setTitile(title: string)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
})
|
||||
|
||||
type iTodo = typeof Todo.Type
|
||||
|
||||
const Store = mst.types.model("Store",
|
||||
{
|
||||
todos: mst.types.array(Todo)
|
||||
},
|
||||
{
|
||||
add(todo: iTodo | Object)
|
||||
{
|
||||
this.todos.push(todo)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// create an instance from a snapshot
|
||||
const store = Store.create(
|
||||
{
|
||||
todos: [{
|
||||
title: "ggg"
|
||||
}]
|
||||
}
|
||||
)
|
||||
let oldStore = mst.getSnapshot(store)
|
||||
store.todos[0].setTitile("hello1")
|
||||
mst.applySnapshot(store, oldStore);
|
||||
|
||||
let paths = [];
|
||||
mst.onPatch(store,
|
||||
p =>
|
||||
{
|
||||
let path;
|
||||
path = p;
|
||||
paths.push(path);
|
||||
},
|
||||
true)
|
||||
store.todos[0].setTitile("hh");
|
||||
|
||||
store.todos[0].setTitile("123");
|
||||
store.todos[0].setTitile("456");
|
||||
store.todos[0].setTitile("hhh");
|
||||
store.todos[0].setTitile("ggg");
|
||||
|
||||
console.log(paths);
|
||||
|
||||
mst.revertPatch(store, _.last(paths))
|
||||
console.log('_.last(paths): ', _.last(paths));
|
||||
console.log(mst.getSnapshot(store));
|
||||
|
||||
console.log(paths);
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,47 @@
|
||||
import * as mst from 'mobx-state-tree';
|
||||
import * as THREE from "three";
|
||||
|
||||
|
||||
const PointData = mst.types.optional(mst.types.array(mst.types.number), [0, 0, 0]);
|
||||
type IPointData = typeof PointData;
|
||||
|
||||
function toVec3(vec: IPointData): THREE.Vector3
|
||||
{
|
||||
return new THREE.Vector3(vec[0], vec[1], vec[2]);
|
||||
}
|
||||
|
||||
export const EntityData = mst.types.model(
|
||||
"Entity",
|
||||
{
|
||||
size: PointData,
|
||||
},
|
||||
{
|
||||
getSize(): THREE.Vector3
|
||||
{
|
||||
return toVec3(this.size);
|
||||
},
|
||||
setSize(x, y, z)
|
||||
{
|
||||
this.size = [x, y, z];
|
||||
},
|
||||
afterCreate()
|
||||
{
|
||||
}
|
||||
}
|
||||
)
|
||||
export type IEntityData = typeof EntityData.Type;
|
||||
|
||||
|
||||
export const LineData = mst.types.compose(
|
||||
"Line",
|
||||
EntityData,
|
||||
{
|
||||
startPoint: PointData,
|
||||
entPoint: PointData,
|
||||
},
|
||||
{
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
//let l = LineData.create();
|
Loading…
Reference in new issue