@astropub/flow
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -0,1 +1,3 @@ | ||
// ----------------------------------------------------------------------------- | ||
export function For<T>(props: ForProps<T>): any | ||
@@ -10,4 +12,6 @@ | ||
// ----------------------------------------------------------------------------- | ||
export function Case<T>(props: CaseProps<T>): any | ||
export function Switch(props: SwitchProps): any | ||
export function Case<T>(props: CaseProps<T>): any | ||
@@ -39,1 +43,7 @@ export interface SwitchProps { | ||
) | ||
// ----------------------------------------------------------------------------- | ||
export function When(props: WhenProps): any | ||
interface WhenProps {} |
@@ -1,3 +0,4 @@ | ||
export { default as Switch } from './AstroSwitch.astro' | ||
export { default as Case } from './AstroCase.astro' | ||
export { default as For } from './AstroFor.astro' | ||
export { default as Switch } from './AstroSwitch.astro' | ||
export { default as When } from './AstroWhen.astro' |
@@ -5,3 +5,3 @@ { | ||
"description": "Use control flow statements in Astro", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"type": "module", | ||
@@ -32,2 +32,3 @@ "license": "CC0-1.0", | ||
"AstroSwitch.astro", | ||
"AstroWhen.astro", | ||
"package.json", | ||
@@ -37,7 +38,13 @@ "shared.js" | ||
"keywords": [ | ||
"astro", | ||
"astro-component", | ||
"astro", | ||
"component", | ||
"ui", | ||
"perf", | ||
"performance", | ||
"condition", | ||
"conditional", | ||
"conditionals", | ||
"conditions", | ||
"component", | ||
"else", | ||
"case", | ||
@@ -48,6 +55,8 @@ "control", | ||
"for", | ||
"if", | ||
"loop", | ||
"of", | ||
"statement", | ||
"switch" | ||
"switch", | ||
"when" | ||
], | ||
@@ -54,0 +63,0 @@ "author": "Jonathan Neal <jonathantneal@hotmail.com>", |
@@ -12,2 +12,11 @@ # Astro Flow | ||
```astro | ||
<When {checkForTruthiness} {alsoCheckForTruthiness}> | ||
<p>Everything was Truthy!</p> | ||
<Fragment slot="else"> | ||
<p>Not everything was truthy...</p> | ||
</When> | ||
``` | ||
```astro | ||
<Switch of={null}> | ||
@@ -41,3 +50,3 @@ <Case of={true}> | ||
--- | ||
import { Case, For, Switch } from '@astropub/flow' | ||
import { Case, For, Switch, When } from '@astropub/flow' | ||
--- | ||
@@ -48,2 +57,6 @@ <For of={items}>{ | ||
<When {true}> | ||
<p>Things are true.</p> | ||
</When> | ||
<Switch of={null}> | ||
@@ -50,0 +63,0 @@ <Case of={true}> |
// @ts-check | ||
/** Symbol used to share data between AstroSwitch and AstroCase. */ | ||
const symbol = Symbol.for('astro-switch') | ||
const $$switch = Symbol.for('astro-switch') | ||
/** @type {Shared[]} Array of shared state to manage AstroSwitch and AstroCase. */ | ||
const shared = globalThis[symbol] = globalThis[symbol] || [] | ||
/** @type {Switch[]} Array of shared state to manage AstroSwitch and AstroCase. */ | ||
export const statesOfSwitch = globalThis[$$switch] = globalThis[$$switch] || [] | ||
export default shared | ||
export function getSwitchState() { | ||
return /** @type {Switch} */ (statesOfSwitch.at(-1)) | ||
} | ||
/** @typedef {{ value: any, hasRenderedCase: boolean, hasRenderedDefault: boolean }} Shared */ | ||
/** @typedef {{ value: any, hasRenderedCase: boolean, hasRenderedDefault: boolean }} Switch */ | ||
/** @typedef {{ value: any, hasRenderedCase: boolean, hasRenderedDefault: boolean }} When */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
6427
9
52
76