Skip to content

Commit

Permalink
Updated Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDoge committed Oct 14, 2024
1 parent 9fda15d commit f68d41e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@purifyjs/core",
"version": "0.0.303",
"version": "0.0.304",
"exports": "./lib/all.ts",
"publish": {
"include": ["lib", "LICENSE", "README.md"]
Expand Down
9 changes: 8 additions & 1 deletion lib/signals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export declare namespace Signal {
* lastAdded.follow(console.log)
* arraySignal.push(123)
* arraySignal.emit() // logs: 123
**/
* ```
*/
public emit(): void
}

Expand Down Expand Up @@ -224,10 +225,12 @@ Signal.Computed = class<T> extends Signal<T> {
* @returns {Signal.State<T>} A new state signal with the given initial value.
*
* @example
* ```ts
* const count = ref(0);
* count.follow(console.log)
* count.val = 5; // logs: 5
* count.val = 10; // logs: 10
* ```
*/
export let ref = <T>(value: T, startStop?: Signal.State.Start<T>): Signal.State<T> =>
new Signal.State(value, startStop)
Expand All @@ -240,11 +243,13 @@ export let ref = <T>(value: T, startStop?: Signal.State.Start<T>): Signal.State<
* @returns {Signal.Computed<T>} A new computed signal.
*
* @example
* ```ts
* const a = ref(1);
* const b = ref(2);
* const sum = computed(() => a.val + b.val);
* sum.follow(console.log)
* a.val++ // logs: 4
* ```
*/
export let computed = <T>(getter: Signal.Computed.Getter<T>): Signal.Computed<T> =>
new Signal.Computed(getter)
Expand All @@ -259,8 +264,10 @@ export let computed = <T>(getter: Signal.Computed.Getter<T>): Signal.Computed<T>
* @returns {Signal<T | U>} A signal that updates when the promise resolves.
*
* @example
* ```ts
* const dataSignal = awaited(fetchDataPromise, null);
* dataSignal.follow((data) => console.log(data)); // logs the resolved data when ready
* ```
*/
export let awaited = <T, const U = null>(
promise: Promise<T>,
Expand Down
14 changes: 10 additions & 4 deletions lib/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ let instancesOf = <T extends (abstract new (...args: never) => unknown)[]>(
* @param members - The members to append to the fragment.
* @returns The created DocumentFragment.
* @example
* let frag = fragment(
* ```ts
* document.body.append(fragment(
* document.createElement('div'),
* div(),
* computed(() => count.val * 2),
* 'Text content'
* );
* ));
* ```
*/
export let fragment = (...members: MemberOf<DocumentFragment>[]): DocumentFragment => {
let fragment = document.createDocumentFragment()
Expand Down Expand Up @@ -99,9 +101,9 @@ export let toAppendable = (
* It separates attributes and properties.
* @example
* let { div, span } = tags;
*
* ```ts
* let { div, span } = tags;
*
* div({ class: 'hello', 'aria-hidden': 'false' })
* .id("my-div")
* .ariaLabel("Hello, World!")
Expand Down Expand Up @@ -228,9 +230,11 @@ export class Builder<T extends HTMLElementWithLifecycle> {
*
* @param element - The element to build.
* @example
* ```ts
* new Builder(myDiv)
* .attributes({ class: 'hello', 'aria-hidden': 'false' })
* .children(span('Hello, World!'));
* ```
*/
constructor(element: T) {
this.element = element
Expand Down Expand Up @@ -279,11 +283,13 @@ export declare namespace Builder {
* @returns The proxy for the Builder instance.
*
* @example
* ```ts
* Builder.Proxy(myDiv)
* .attributes({ class: 'hello', 'aria-hidden': 'false' })
* .children(span('Hello, World!'));
* .onclick(() => console.log('clicked!'));
* .ariaLabel("Hello, World!");
* ```
*/
function Proxy<T extends HTMLElementWithLifecycle>(element: T): Builder.Proxy<T>
}
Expand Down

0 comments on commit f68d41e

Please sign in to comment.