Made several options functions optional

This commit is contained in:
thepaperpilot 2022-04-24 17:05:28 -05:00
parent aae6455ea6
commit 94a7f41fd1
7 changed files with 13 additions and 14 deletions

View file

@ -68,11 +68,11 @@ export type GenericAchievement = Replace<
>; >;
export function createAchievement<T extends AchievementOptions>( export function createAchievement<T extends AchievementOptions>(
optionsFunc: OptionsFunc<T, Achievement<T>, BaseAchievement> optionsFunc?: OptionsFunc<T, Achievement<T>, BaseAchievement>
): Achievement<T> { ): Achievement<T> {
const earned = persistent<boolean>(false); const earned = persistent<boolean>(false);
return createLazyProxy(() => { return createLazyProxy(() => {
const achievement = optionsFunc(); const achievement = optionsFunc?.() ?? ({} as ReturnType<NonNullable<typeof optionsFunc>>);
achievement.id = getUniqueID("achievement-"); achievement.id = getUniqueID("achievement-");
achievement.type = AchievementType; achievement.type = AchievementType;
achievement[Component] = AchievementComponent; achievement[Component] = AchievementComponent;

View file

@ -70,10 +70,10 @@ export type GenericClickable = Replace<
>; >;
export function createClickable<T extends ClickableOptions>( export function createClickable<T extends ClickableOptions>(
optionsFunc: OptionsFunc<T, Clickable<T>, BaseClickable> optionsFunc?: OptionsFunc<T, Clickable<T>, BaseClickable>
): Clickable<T> { ): Clickable<T> {
return createLazyProxy(() => { return createLazyProxy(() => {
const clickable = optionsFunc(); const clickable = optionsFunc?.() ?? ({} as ReturnType<NonNullable<typeof optionsFunc>>);
clickable.id = getUniqueID("clickable-"); clickable.id = getUniqueID("clickable-");
clickable.type = ClickableType; clickable.type = ClickableType;
clickable[Component] = ClickableComponent; clickable[Component] = ClickableComponent;

View file

@ -20,7 +20,7 @@ export interface Link extends SVGAttributes {
} }
export interface LinksOptions { export interface LinksOptions {
links?: Computable<Link[]>; links: Computable<Link[]>;
} }
export interface BaseLinks { export interface BaseLinks {

View file

@ -84,11 +84,11 @@ export type GenericMilestone = Replace<
>; >;
export function createMilestone<T extends MilestoneOptions>( export function createMilestone<T extends MilestoneOptions>(
optionsFunc: OptionsFunc<T, Milestone<T>, BaseMilestone> optionsFunc?: OptionsFunc<T, Milestone<T>, BaseMilestone>
): Milestone<T> { ): Milestone<T> {
const earned = persistent<boolean>(false); const earned = persistent<boolean>(false);
return createLazyProxy(persistent => { return createLazyProxy(() => {
const milestone = Object.assign(persistent, optionsFunc()); const milestone = optionsFunc?.() ?? ({} as ReturnType<NonNullable<typeof optionsFunc>>);
milestone.id = getUniqueID("milestone-"); milestone.id = getUniqueID("milestone-");
milestone.type = MilestoneType; milestone.type = MilestoneType;
milestone[Component] = MilestoneComponent; milestone[Component] = MilestoneComponent;

View file

@ -42,10 +42,10 @@ export type Particles<T extends ParticlesOptions> = Replace<
export type GenericParticles = Particles<ParticlesOptions>; export type GenericParticles = Particles<ParticlesOptions>;
export function createParticles<T extends ParticlesOptions>( export function createParticles<T extends ParticlesOptions>(
optionsFunc: OptionsFunc<T, Particles<T>, BaseParticles> optionsFunc?: OptionsFunc<T, Particles<T>, BaseParticles>
): Particles<T> { ): Particles<T> {
return createLazyProxy(() => { return createLazyProxy(() => {
const particles = optionsFunc(); const particles = optionsFunc?.() ?? ({} as ReturnType<NonNullable<typeof optionsFunc>>);
particles.id = getUniqueID("particles-"); particles.id = getUniqueID("particles-");
particles.type = ParticlesType; particles.type = ParticlesType;
particles[Component] = ParticlesComponent; particles[Component] = ParticlesComponent;

View file

@ -101,8 +101,7 @@ export function createTabFamily<T extends TabFamilyOptions>(
const selected = persistent(Object.keys(tabs)[0]); const selected = persistent(Object.keys(tabs)[0]);
return createLazyProxy(() => { return createLazyProxy(() => {
const tabFamily = const tabFamily = optionsFunc?.() ?? ({} as ReturnType<NonNullable<typeof optionsFunc>>);
optionsFunc?.() || ({} as ReturnType<OptionsFunc<T, TabFamily<T>, BaseTabFamily>>);
tabFamily.id = getUniqueID("tabFamily-"); tabFamily.id = getUniqueID("tabFamily-");
tabFamily.type = TabFamilyType; tabFamily.type = TabFamilyType;

View file

@ -73,10 +73,10 @@ export type GenericTreeNode = Replace<
>; >;
export function createTreeNode<T extends TreeNodeOptions>( export function createTreeNode<T extends TreeNodeOptions>(
optionsFunc: OptionsFunc<T, TreeNode<T>, BaseTreeNode> optionsFunc?: OptionsFunc<T, TreeNode<T>, BaseTreeNode>
): TreeNode<T> { ): TreeNode<T> {
return createLazyProxy(() => { return createLazyProxy(() => {
const treeNode = optionsFunc(); const treeNode = optionsFunc?.() ?? ({} as ReturnType<NonNullable<typeof optionsFunc>>);
treeNode.id = getUniqueID("treeNode-"); treeNode.id = getUniqueID("treeNode-");
treeNode.type = TreeNodeType; treeNode.type = TreeNodeType;
treeNode[Component] = TreeNodeComponent; treeNode[Component] = TreeNodeComponent;