Compare commits

..

5 Commits
main ... goSJW

6 changed files with 30 additions and 73 deletions

View File

@ -1,11 +0,0 @@
# Revision history for UnitJS
## 0.1.1 -- 2022-08-09
* Package UnitJS for [guix](https://guix.gnu.org/)
* Fix state bug in Async's sequences and bindings
* Generalize support for events in Dom element maker
## 0.1.0 -- 2020-05-17
* Release UnitJS as a [SJW](https://git.marvid.fr/Tissevert/SJW) package still useable as a standalone script.

View File

@ -1,49 +1,43 @@
# UnitJS
UnitJS is a tiny Javascript framework to write web applications. It provides
four essential modules to deal with asynchronous functions (technically, it's a
monad obtained by currifying the CPS functions of Javascript like
`setTimeout`), value caching, DOM manipulation and basic functional needs like
composition or object projections.
UnitJS is a tiny Javascript framework to write web applications. It provides four essential modules to deal with asynchronous functions (technically, it's a monad obtained by currifying the CPS functions of Javascript like `setTimeout`), value caching, DOM manipulation and basic functional needs like composition or object projections.
## Usage
## How to use it in your project
### With [SJW](https://git.marvid.fr/Tissevert/SJW)
### As a [`SJW`](https://git.marvid.fr/Tissevert/SJW) package.
UnitJS comes as a SJW package. You can install it by copying the `src/` directory of this repository to your package database by issuing the following command from the current directory :
#### With [`guix`](https://guix.gnu.org/)
```
$ cp -r src/ ~/.sjw/unitJS
```
The easiest way to use it in your web projects is to simply [package them with
`guix`](https://git.marvid.fr/Tissevert/SJW#how-not-to-install).
Then, using unitJS in your projects is as simple as writing :
#### Otherwise
```
import * as Async from UnitJS.Async;
```
You can follow [these
instructions](https://git.marvid.fr/Tissevert/SJW#when-guix-is-not-an-option)
to use it without `guix`.
in any module if you want to use the `Async` module for instance and compile your code using the `--include` option of `sjw` with package `unitJS` :
### Without `SJW`
```
$ sjw -I unitJS your/code/src -o your/code/main.js
```
If you don't want to or can't use SJW, it's still possible to use UnitJS by
generating a single script that can then be loaded from your web page like this
:
Note that all modules have their path prefixed by a common `UnitJS` component and that SJW will only include the modules actually used in your code, not all of UnitJS.
### As a standalone JS script
If you don't want to or can't use SJW, it's still possible to use UnitJS by generating a single script that can then be loaded from your web page like this :
```
<script src="/path/to/unit.js"></script>
```
The file `unit.js` can be easily generated with `make`, which actually just
calls the `unit.js.tpl` script. Note that you can still generate custom
«partial» versions of `unit.js` if you don't use all of it by overriding the
`SRC` variable of the `Makefile` like so :
The file `unit.js` can be easily generated with `make`, which actually just calls the `unit.js.tpl` script. Note that you can still generate custom «partial» versions of `unit.js` if you don't use all of it by overriding the `SRC` variable of the `Makefile` like so :
```
make SRC="src/UnitJS/Dom.js src/UnitJS/Cache.js"
```
or by manually calling `./unit.js.tpl` with the files you want, like the
`Makefile` does.
When used that way, the `UnitJS` library will be available to your Javascript
code as a global variable `unitJS` containing each of the modules (`Async`,
`Dom`, etc.) as an attribute.
or by manually calling `./unit.js.tpl` with the files you want, like the `Makefile` does.

View File

@ -1,24 +0,0 @@
(use-modules (guix build-system copy)
(guix gexp)
(guix git-download)
(guix licenses)
(guix packages))
(let ((%source-dir (dirname (current-filename))))
(package
(name "sjw-unitJS")
(version "devel")
(source (local-file %source-dir
#:recursive? #t
#:select? (git-predicate %source-dir)))
(build-system copy-build-system)
(arguments
'(#:install-plan '(("src" "lib/SJW/unitJS"))))
(home-page "https://git.marvid.fr/Tissevert/UnitJS")
(synopsis "The Simple Javascript Wrench.")
(description
"A collection of JS modules to write simple web applications. It covers
the basics, providing asynchronous operations without any need for
promises-support from the browser as well as primitives to create DOM
elements and basic functional-programming tooling.")
(license gpl3+)))

View File

@ -18,14 +18,14 @@ function apply(f, x) {
}
function bind() {
var m, steps;
var m, steps, i;
if(arguments.length < 1) {
return wrap();
}
m = arguments[0];
steps = arguments;
i = 1;
return function(f) {
var i = 1;
var step = function(x) {
if(i < steps.length) {
steps[i++](x)(step);
@ -87,8 +87,8 @@ function run() {
function sequence() {
var steps = arguments;
var i = 0;
return function(f) {
var i = 0;
var step = function(x) {
if(i < steps.length) {
steps[i++](step);

View File

@ -22,13 +22,11 @@ function make(tag, properties, children) {
case "maxlength":
e.setAttribute("maxlength", value);
break;
case "onClick":
e.addEventListener("click", value);
break;;
default:
var matched = key.match(/on([A-Z]\w+)/);
if(matched) {
e.addEventListener(matched[1].toLowerCase(), value);
} else {
e[key] = value;
}
e[key] = value;
}
}
for(var i = 0; i < children.length; i++) {

View File

@ -30,7 +30,7 @@ EOF
cat <<EOF
var unitJS = (function() {
return {
$(printf "${MODULES}" | sed -e 's|:|,\n|g' -e 's|[^,\n]\+|&: &()|g' | indent | indent)
$(printf "${MODULES}" | sed -e 's|:|,\n|g' -e 's|[^,\n]\+|&: &|g' | indent | indent)
};
$(for file in "${@}"; do includeModule "${file}"; done | indent)
})();