-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds SyncronizationSafeLogseq Wrapper for accessing logseq api in order to fix #58
- Loading branch information
1 parent
5029f6c
commit 0e4f750
Showing
8 changed files
with
83 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { BlockEntity, BlockIdentity, EntityID, PageIdentity } from "@logseq/libs/dist/LSPlugin"; | ||
import AwaitLock from "await-lock"; | ||
/*** | ||
* Syncronization-safe logseq api wrapper for the Logseq plugin | ||
* */ | ||
|
||
let getLogseqLock = new AwaitLock(); | ||
export namespace SyncronizationSafeLogseq { | ||
export class Editor { | ||
static async getBlock(srcBlock: BlockIdentity | EntityID, opts?: Partial<{ includeChildren: boolean; }>): Promise<BlockEntity | null> { | ||
let block = null; | ||
await getLogseqLock.acquireAsync(); | ||
try {block = await logseq.Editor.getBlock(srcBlock, opts);} | ||
catch(e) { console.error(e); } | ||
finally { getLogseqLock.release(); } | ||
return block; | ||
} | ||
|
||
static async getPage(srcPage: PageIdentity | EntityID): Promise<PageIdentity | null> { | ||
let page = null; | ||
await getLogseqLock.acquireAsync(); | ||
try {page = await logseq.Editor.getPage(srcPage);} | ||
catch(e) { console.error(e); } | ||
finally { getLogseqLock.release(); } | ||
return page; | ||
} | ||
|
||
static async getPageBlocksTree(srcPage: PageIdentity): Promise<Array<BlockEntity>> { | ||
let pageBlockTree = null; | ||
await getLogseqLock.acquireAsync(); | ||
try {pageBlockTree = await logseq.Editor.getPageBlocksTree(srcPage);} | ||
catch(e) { console.error(e); } | ||
finally { getLogseqLock.release(); } | ||
return pageBlockTree; | ||
} | ||
|
||
static async upsertBlockProperty(block: BlockIdentity, key: string, value: any): Promise<void> { | ||
await getLogseqLock.acquireAsync(); | ||
try {await logseq.Editor.upsertBlockProperty(block, key, value);} | ||
catch(e) { console.error(e); } | ||
finally { getLogseqLock.release(); } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters