From 2d03f044f4b20ed3283311ce58d08d7b7ec27eeb Mon Sep 17 00:00:00 2001 From: David First Date: Mon, 18 Mar 2024 14:31:26 -0400 Subject: [PATCH] introduce a new API "getCurrentSnap()" for the Component object (#8677) It was requested a while ago by Ran/Guy. --- scopes/component/component/component.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scopes/component/component/component.ts b/scopes/component/component/component.ts index b60d0d5d9659..52966da6e53a 100644 --- a/scopes/component/component/component.ts +++ b/scopes/component/component/component.ts @@ -311,6 +311,16 @@ export class Component implements IComponent { return this.id.version; } + /** + * in case a component is new, it returns undefined. + * otherwise, it returns the Snap object (hash/parents/log) of the current component (according to the version in the id) + */ + async getCurrentSnap(): Promise { + const snap = this.getSnapHash(); + if (!snap) return undefined; + return this.loadSnap(snap); + } + /** * checkout the component to a different version in its working tree. */