2.6.0 • Published 4 days ago

@targoninc/fjs v2.6.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 days ago

fjs (factory js)

URL for latest version: https://fjs.targoninc.com/f.js

npm Package Docker Image

npm package

https://www.npmjs.com/package/@targoninc/fjs

Installation

npm install @targoninc/fjs

Usage

As an example, we'll create two files: test.mjs and test.html.

test.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>FJS Test</title>
    <style>
        body, span {
            padding: 10px;
            display: block;
            width: max-content;
        }

        .border {
            border: 1px solid black;
        }
    </style>
</head>
<body>
    <div id="app"></div>
    <script src="test.mjs" type="module"></script>
</body>
</html>

test.mjs

import { create, signal } from '@targon/fjs';

// elements make sense to be created in a function
function testElement(classes = []) {
    const text = signal('test');
    
    return create("span")
        .classes('border', ...classes)
        .attributes('data-test', 'test', 'data-test2', 'test2')
        // signals can be passed to any attribute and they will be updated when the signal's value is updated
        .text(text)
        .onclick(() => {
            // signals can be updated to update the text of the element
            text.value = 'clicked';
        })
        // children can be created by passing them as arguments to the children method
        .children(testChild(text))
        .build();
}

function testChild(text) {
    const childText = signal(text.value + " in child");
    // subscribe to the parent signal to update the child signal
    text.subscribe((value) => {
        childText.value = value + " in child";
    });
    
    return create("span")
        .classes('border')
        .text(childText)
        .build();
}

const app = document.querySelector('#app');
app.appendChild(testElement(['testClass']));
2.6.0

4 days ago

2.5.1

28 days ago

2.5.0

30 days ago

2.4.0

1 month ago

2.3.1

2 months ago

2.2.1

2 months ago

2.2.0

2 months ago

2.1.1

2 months ago

2.1.0

2 months ago

2.0.1

3 months ago

2.0.0

3 months ago

1.2.2

3 months ago

1.2.1

4 months ago

1.2.0

4 months ago

1.1.9

4 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.1.8

7 months ago

1.1.7

7 months ago

1.0.8

9 months ago

1.1.6

7 months ago

1.1.5

7 months ago

1.1.4

7 months ago

1.1.3

7 months ago

1.1.2

7 months ago

1.0.7

12 months ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago