Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.log
*.lock
*.bs.js
*.res.js

node_modules/
lib/
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rescript-7guis",
"version": "0.0.0",
"version": "0.1.0",
"type": "module",
"private": true,
"license": "MIT",
Expand All @@ -15,10 +15,11 @@
"serve": "serve"
},
"dependencies": {
"rescript": "^10.0.1"
"@rescript/core": "^0.6.0",
"rescript": "^11.0.1"
},
"devDependencies": {
"serve": "^14.1.1",
"serve": "^14.2.1",
"uvu": "^0.5.6"
},
"packageManager": "yarn@3.2.4"
Expand Down
9 changes: 7 additions & 2 deletions bsconfig.json → rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"in-source": true
}
],
"suffix": ".bs.js",
"bs-dependencies": []
"suffix": ".res.js",
"bs-dependencies": [
"@rescript/core"
],
"bsc-flags": [
"-open RescriptCore"
]
}
5 changes: 3 additions & 2 deletions tasks/circle.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
<script type="importmap">
{
"imports": {
"rescript/": "/node_modules/rescript/"
"rescript/": "/node_modules/rescript/",
"@rescript/": "/node_modules/@rescript/"
}
}
</script>

<script type="module">
import { CircleDrawer, Circle } from './circle.bs.js';
import { CircleDrawer, Circle } from './circle.res.js';

let $canvas = document.getElementById('canvas');
let $undo = document.getElementById('undo');
Expand Down
4 changes: 0 additions & 4 deletions tasks/circle.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module Point = {
}

let distance = (p1, p2) => {
open Belt

let dx = p1.x - p2.x
let dy = p1.y - p2.y

Expand Down Expand Up @@ -148,8 +146,6 @@ module CircleDrawer = {
})

let reduce = (state, action) => {
open Belt

switch (state, action) {
| (Idle(context) | Hover({context}), MouseMove(mouse)) => {
let context = {...context, mouse}
Expand Down
2 changes: 1 addition & 1 deletion tasks/circle.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert';

import { CircleDrawer } from './circle.bs.js';
import { CircleDrawer } from './circle.res.js';

test('transferHead', () => {
let { transferHead, arrayToList, listToArray } = CircleDrawer.Util;
Expand Down
5 changes: 3 additions & 2 deletions tasks/counter.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
<script type="importmap">
{
"imports": {
"rescript/": "/node_modules/rescript/"
"rescript/": "/node_modules/rescript/",
"@rescript/": "/node_modules/@rescript/"
}
}
</script>

<script type="module">
import { Counter } from './counter.bs.js';
import { Counter } from './counter.res.js';

let $count = document.getElementById('count');
let $increase = document.getElementById('increase');
Expand Down
5 changes: 3 additions & 2 deletions tasks/crud.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
<script type="importmap">
{
"imports": {
"rescript/": "/node_modules/rescript/"
"rescript/": "/node_modules/rescript/",
"@rescript/": "/node_modules/@rescript/"
}
}
</script>

<script type="module">
import { CRUD } from './crud.bs.js';
import { CRUD } from './crud.res.js';

let $entries = document.getElementById('entries');
let $filter = document.getElementById('filter');
Expand Down
23 changes: 15 additions & 8 deletions tasks/crud.res
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ module CRUD = {
}

let reduce = (state, action) => {
open Belt
switch (state, action) {
| ({id_seq, name, surname, entries}, CreateEntry) => {
let id = id_seq + 1
Expand Down Expand Up @@ -86,7 +85,7 @@ module CRUD = {
| ({entries}, DeleteEntry(id)) => {
let state = {
...state,
entries: entries->Array.keep(entry =>
entries: entries->Belt.Array.keep(entry =>
switch entry {
| entry if entry.id == id => false
| _ => true
Expand Down Expand Up @@ -122,19 +121,27 @@ module CRUD = {
{...program, state}
}

let updateEntry = (program, id) => {
let state = program->dispatch(UpdateEntry(id))
{...program, state}
let updateEntry = (program) => {
switch program.state.selected {
| None => program
| Some(entry) =>
let state = program->dispatch(UpdateEntry(entry.id))
{...program, state}
}
}

let selectEntry = (program, id) => {
let state = program->dispatch(SelectEntry(id))
{...program, state}
}

let deleteEntry = (program, id) => {
let state = program->dispatch(DeleteEntry(id))
{...program, state}
let deleteEntry = (program) => {
switch program.state.selected {
| None => program
| Some(entry) =>
let state = program->dispatch(DeleteEntry(entry.id))
{...program, state}
}
}

let changeName = (program, name) => {
Expand Down
5 changes: 3 additions & 2 deletions tasks/flight.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
<script type="importmap">
{
"imports": {
"rescript/": "/node_modules/rescript/"
"rescript/": "/node_modules/rescript/",
"@rescript/": "/node_modules/@rescript/"
}
}
</script>

<script type="module">
import { FlightBooker, Field } from './flight.bs.js';
import { FlightBooker, Field } from './flight.res.js';

let $form = document.querySelector('form');
let $type = document.getElementById('type');
Expand Down
5 changes: 3 additions & 2 deletions tasks/temp.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
<script type="importmap">
{
"imports": {
"rescript/": "/node_modules/rescript/"
"rescript/": "/node_modules/rescript/",
"@rescript/": "/node_modules/@rescript/"
}
}
</script>

<script type="module">
import { TemperatureConverter } from './temp.bs.js';
import { TemperatureConverter } from './temp.res.js';

let $ce = document.getElementById('ce');
let $fa = document.getElementById('fa');
Expand Down
5 changes: 3 additions & 2 deletions tasks/timer.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
<script type="importmap">
{
"imports": {
"rescript/": "/node_modules/rescript/"
"rescript/": "/node_modules/rescript/",
"@rescript/": "/node_modules/@rescript/"
}
}
</script>

<script type="module">
import { Timer } from './timer.bs.js';
import { Timer } from './timer.res.js';

let $slider = document.getElementById('slider');
let $time = document.getElementById('time');
Expand Down
2 changes: 0 additions & 2 deletions tasks/timer.res
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ module Timer = {
let maxDuration = 60 * 1000

let durationToPercent = duration => {
open Belt
(Int.toFloat(duration) /. Int.toFloat(maxDuration) *. 100.)->Int.fromFloat
}

let percentToDuration = pct => {
open Belt
(pct /. 100. *. Int.toFloat(maxDuration))->Int.fromFloat
}

Expand Down