Test.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { types } from "mobx-state-tree";
  2. const Region = types.model({
  3. name: types.string,
  4. });
  5. export const ImageRegion = types.compose(
  6. "Image",
  7. Region,
  8. types
  9. .model({
  10. id: types.identifier,
  11. type: types.literal("image"),
  12. })
  13. .actions(() => ({
  14. draw() {
  15. // console.log("DRAW", self.id);
  16. },
  17. })),
  18. );
  19. export const TextRegion = types.compose(
  20. "Text",
  21. Region,
  22. types
  23. .model({
  24. id: types.identifier,
  25. type: types.literal("text"),
  26. })
  27. .actions(() => ({
  28. select() {
  29. // console.log("SELECT", self.id);
  30. },
  31. })),
  32. );
  33. // const HyperTextRegion = types.model({
  34. // id: types.identifier,
  35. // type: types.literal(""),
  36. // });
  37. // const AudioRegion = types.model({
  38. // id: types.identifier,
  39. // type: types.literal(""),
  40. // });
  41. const TestRaw = types.model("TestRaw", {
  42. regions: types.array(types.union(ImageRegion, TextRegion)),
  43. // inheritance: types.array(Region), // wrong :(
  44. meta: types.number,
  45. });
  46. const TestMeta = types.model({
  47. meta: types.model({
  48. width: 120,
  49. height: 100,
  50. }),
  51. });
  52. const Test = types.compose("Test", TestRaw, TestMeta);
  53. export default Test;