diff --git a/__test__/entry.test.ts b/__test__/entry.test.ts index 5fdfff9..a7e506b 100644 --- a/__test__/entry.test.ts +++ b/__test__/entry.test.ts @@ -57,6 +57,17 @@ describe("Entry", () => { expect(testData.entry).toEqual(entry.getData()); }); + it("getDraftData", () => { + entry._changedData = { title: "Draft Title", content: "Draft Content" }; + expect(entry.getDraftData()).toEqual({ + title: "Draft Title", + content: "Draft Content", + }); + + entry._changedData = {}; + expect(entry.getDraftData()).toEqual({}); + }); + describe("getField", () => { it("getField undefined", function () { const uid = "group1.group"; @@ -133,7 +144,7 @@ describe("Entry", () => { }); it("should use custom Field instance if internal flag is set", () => { const fieldInstance: any = jest.fn(); - entry = new Entry(testData as any, connection as any, emitter ,{ + entry = new Entry(testData as any, connection as any, emitter, { _internalFlags: { FieldInstance: fieldInstance, }, @@ -182,4 +193,4 @@ describe("Entry", () => { "Callback must be a function" ); }); -}); \ No newline at end of file +}); diff --git a/src/entry.ts b/src/entry.ts index b8bb4d6..279016a 100755 --- a/src/entry.ts +++ b/src/entry.ts @@ -91,6 +91,19 @@ class Entry { return this._data; } + /** + * Gets the draft data of the current entry. + * If no changes are available, returns an empty object. + * @return {Object} Returns the draft entry data (_changedData) if available; otherwise, returns an empty object. + */ + getDraftData() { + if (this._changedData && Object.keys(this._changedData).length > 0) { + return this._changedData; + } else { + return {}; + } + } + /** * *