snapshot.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. export class Snapshot {
  2. constructor(options) {
  3. const { id, docChanges, docs, msgType, type } = options;
  4. let cachedDocChanges;
  5. let cachedDocs;
  6. Object.defineProperties(this, {
  7. id: {
  8. get: () => id,
  9. enumerable: true
  10. },
  11. docChanges: {
  12. get: () => {
  13. if (!cachedDocChanges) {
  14. cachedDocChanges = JSON.parse(JSON.stringify(docChanges));
  15. }
  16. return cachedDocChanges;
  17. },
  18. enumerable: true
  19. },
  20. docs: {
  21. get: () => {
  22. if (!cachedDocs) {
  23. cachedDocs = JSON.parse(JSON.stringify(docs));
  24. }
  25. return cachedDocs;
  26. },
  27. enumerable: true
  28. },
  29. msgType: {
  30. get: () => msgType,
  31. enumerable: true
  32. },
  33. type: {
  34. get: () => type,
  35. enumerable: true
  36. }
  37. });
  38. }
  39. }