-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add transform util func to async-node-plugin
- Loading branch information
1 parent
c582503
commit 964cc11
Showing
9 changed files
with
77 additions
and
29 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
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,32 @@ | ||
import { Builder } from "@player-ui/player"; | ||
import { v4 as uuid } from "uuid"; | ||
import type { AsyncTransformFunc } from "./types"; | ||
|
||
export const asyncTransform: AsyncTransformFunc = ( | ||
asset, | ||
transformedAssetType, | ||
wrapperAssetType, | ||
) => { | ||
const id = uuid(); | ||
|
||
const assetNode = Builder.asset({ | ||
...asset.value, | ||
type: transformedAssetType, | ||
}); | ||
|
||
const asyncNode = Builder.asyncNode(id); | ||
const multiNode = Builder.multiNode( | ||
asset.value.flatten, | ||
assetNode, | ||
asyncNode, | ||
); | ||
|
||
const wrapperAsset = Builder.asset({ | ||
id: wrapperAssetType + "-" + id, | ||
type: wrapperAssetType, | ||
}); | ||
|
||
Builder.addChild(wrapperAsset, ["values"], multiNode); | ||
|
||
return wrapperAsset; | ||
}; |
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 |
---|---|---|
@@ -1,6 +1,21 @@ | ||
import type { Node } from "@player-ui/player"; | ||
import type { AssetWrapper, Asset, Node } from "@player-ui/player"; | ||
|
||
export type AsyncNodeHandler = ( | ||
node: Node.Node, | ||
update: (object: any) => void, | ||
) => void; | ||
|
||
export interface AsyncNodeWrapperAsset extends Asset { | ||
/** The string value to show */ | ||
values?: Array<AssetWrapper> | Array<Asset>; | ||
} | ||
|
||
export interface AssetType extends Asset { | ||
/** Flatten flag */ | ||
flatten?: boolean | false; | ||
} | ||
|
||
export type AsyncTransformFunc = ( | ||
asset: Node.Asset<AssetType> | Node.View<AssetType>, | ||
transformedAssetType: string, | ||
) => Node.Node; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.