Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
ee320d90f3 | |||
561431e5f7 | |||
f0bd320683 | |||
fcf5bdc55b | |||
3862a866fd |
11
CHANGELOG.md
11
CHANGELOG.md
|
@ -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.
|
|
50
README.md
50
README.md
|
@ -1,49 +1,43 @@
|
||||||
# UnitJS
|
# UnitJS
|
||||||
|
|
||||||
UnitJS is a tiny Javascript framework to write web applications. It provides
|
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.
|
||||||
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
|
Then, using unitJS in your projects is as simple as writing :
|
||||||
`guix`](https://git.marvid.fr/Tissevert/SJW#how-not-to-install).
|
|
||||||
|
|
||||||
#### Otherwise
|
```
|
||||||
|
import * as Async from UnitJS.Async;
|
||||||
|
```
|
||||||
|
|
||||||
You can follow [these
|
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` :
|
||||||
instructions](https://git.marvid.fr/Tissevert/SJW#when-guix-is-not-an-option)
|
|
||||||
to use it without `guix`.
|
|
||||||
|
|
||||||
### 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
|
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.
|
||||||
generating a single script that can then be loaded from your web page like this
|
|
||||||
:
|
### 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>
|
<script src="/path/to/unit.js"></script>
|
||||||
```
|
```
|
||||||
|
|
||||||
The file `unit.js` can be easily generated with `make`, which actually just
|
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 :
|
||||||
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"
|
make SRC="src/UnitJS/Dom.js src/UnitJS/Cache.js"
|
||||||
```
|
```
|
||||||
|
|
||||||
or by manually calling `./unit.js.tpl` with the files you want, like the
|
or by manually calling `./unit.js.tpl` with the files you want, like the `Makefile` does.
|
||||||
`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.
|
|
||||||
|
|
24
guix.scm
24
guix.scm
|
@ -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+)))
|
|
|
@ -18,14 +18,14 @@ function apply(f, x) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function bind() {
|
function bind() {
|
||||||
var m, steps;
|
var m, steps, i;
|
||||||
if(arguments.length < 1) {
|
if(arguments.length < 1) {
|
||||||
return wrap();
|
return wrap();
|
||||||
}
|
}
|
||||||
m = arguments[0];
|
m = arguments[0];
|
||||||
steps = arguments;
|
steps = arguments;
|
||||||
|
i = 1;
|
||||||
return function(f) {
|
return function(f) {
|
||||||
var i = 1;
|
|
||||||
var step = function(x) {
|
var step = function(x) {
|
||||||
if(i < steps.length) {
|
if(i < steps.length) {
|
||||||
steps[i++](x)(step);
|
steps[i++](x)(step);
|
||||||
|
@ -87,8 +87,8 @@ function run() {
|
||||||
|
|
||||||
function sequence() {
|
function sequence() {
|
||||||
var steps = arguments;
|
var steps = arguments;
|
||||||
return function(f) {
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
return function(f) {
|
||||||
var step = function(x) {
|
var step = function(x) {
|
||||||
if(i < steps.length) {
|
if(i < steps.length) {
|
||||||
steps[i++](step);
|
steps[i++](step);
|
||||||
|
|
|
@ -22,15 +22,13 @@ function make(tag, properties, children) {
|
||||||
case "maxlength":
|
case "maxlength":
|
||||||
e.setAttribute("maxlength", value);
|
e.setAttribute("maxlength", value);
|
||||||
break;
|
break;
|
||||||
|
case "onClick":
|
||||||
|
e.addEventListener("click", value);
|
||||||
|
break;;
|
||||||
default:
|
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++) {
|
for(var i = 0; i < children.length; i++) {
|
||||||
e.appendChild(children[i]);
|
e.appendChild(children[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ EOF
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
var unitJS = (function() {
|
var unitJS = (function() {
|
||||||
return {
|
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)
|
$(for file in "${@}"; do includeModule "${file}"; done | indent)
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user