加入Jest 加入MST 加入数据结构

pull/7/head
ChenX 7 years ago
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);

6219
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -7,7 +7,8 @@
"dev": "webpack-dev-server",
"dts": "tcm src -o ./src/UI/css_dts",
"build": "webpack --config dll.config.js &&webpack",
"i": "npm i && npm i -dev"
"i": "npm i && npm i -dev",
"test": "jest"
},
"private": true,
"author": "",
@ -40,7 +41,11 @@
"typings-for-css-modules-loader": "^1.5.0",
"url-loader": "^0.5.9",
"webpack": "^3.3.0",
"webpack-dev-server": "^2.5.1"
"webpack-dev-server": "^2.5.1",
"ts-jest": "^20.0.7",
"@types/jest": "^20.0.5",
"jest": "^20.0.4",
"jest-environment-node-debug": "^2.0.0"
},
"dependencies": {
"css-element-queries": "^0.4.0",
@ -50,10 +55,22 @@
"lodash": "^4.17.4",
"mobx": "^3.2.1",
"mobx-react": "^4.2.2",
"mobx-state-tree": "^0.9.5",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"stats.js": "^0.17.0",
"three": "^0.85.2",
"xaop": "^1.1.5"
},
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__test__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
]
}
}

@ -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…
Cancel
Save