Skip to content

Commit 9d9c913

Browse files
author
Alex Fedoseev
authored
Merge pull request #19 from MinimaHQ/chore
Update deps, add `cmp` function to `DndEntry` interface
2 parents a8d9b5d + 48a56b5 commit 9d9c913

26 files changed

+489
-433
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# History
22

3+
## 2.0.0
4+
* **[ BREAKING ]** Modules of `DndEntry` type must provide `cmp` function to avoid polymorphic comparison. See [this diff](https://github.com/MinimaHQ/re-dnd/commit/238a0abab8ad88a7c643c0b022c49887c025a89b) for details.
5+
* **[ BREAKING ]** Minimum required version of `bs-platform` is `7.1.1`.
6+
* **[ BREAKING ]** Minimum required version of `reason-react` is `0.8.0`.
7+
38
## 1.2.0
49
* `bs-platform` updated to `v7`.
510
* `bs-log` updated to `v1`.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Drag & drop for [`reason-react`](https://reasonml.github.io/reason-react/).
2020

2121
```shell
2222
# yarn
23-
yarn add re-dnd@next
23+
yarn add re-dnd
2424
# or npm
25-
npm install --save re-dnd@next
25+
npm install --save re-dnd
2626
```
2727

2828
Then add it to `bsconfig.json`:
@@ -40,7 +40,7 @@ Then add it to `bsconfig.json`:
4040

4141
## Examples
4242
* Demos: [`live`](https://re-dnd.now.sh) | [`sources`](./examples)
43-
* @Production: [`Minima`](https://minima.app)
43+
* Production app: [`Minima`](https://minima.app)
4444

4545
## State
4646
🚧 The library is not feature-complete and some features/apis might be missing.<br>

bsconfig.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
"react-jsx": 3
1818
},
1919
"refmt": 3,
20-
"bsc-flags": ["-w -45", "-open Belt"],
20+
"bsc-flags": ["-open Belt"],
2121
"ppx-flags": [
2222
["bs-log/ppx", "--lib=re-dnd"],
2323
],
2424
"package-specs": {
2525
"module": "es6",
2626
"in-source": true
2727
},
28-
"suffix": ".bs.js"
28+
"suffix": ".bs.js",
29+
"warnings": {
30+
"number": "+A-40-42-44"
31+
}
2932
}

docs/01-GettingStartedGuide.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ To create components that handle all drag & drop business, we need to call `Dnd.
3232
module Items = Dnd.Make(Item, Container);
3333
```
3434

35-
This code won't compile yet because we need to provide two modules to the `Dnd.Make` functor:
35+
This code wouldn't compile yet because we need to provide two modules to the `Dnd.Make` functor:
3636

3737
- `Item`: configuration for draggable item.
3838
- `Container`: configuration for droppable container, which contains draggable items.
@@ -42,18 +42,21 @@ Both of these modules has the same signature:
4242
```reason
4343
type t;
4444
let eq: (t, t) => bool;
45+
let cmp: (t, t) => int;
4546
```
4647

4748
Basically, functor asks you to answer the following questions:
4849
1. What the thing is? _Answer: type `t`._
49-
1. And when two things given, do those equal or not? _Answer: `eq` function._
50+
1. When two things given, do those equal or not? _Answer: `eq` function._
51+
1. When two things given, how to compare those? _Answer: `cmp` function._
5052

5153
Let's start with very simple (and in general not 100% safe) implementation of `Item` container:
5254

5355
```reason
5456
module Item = {
5557
type t = item; // `item` is a type alias we defined above which is resolved to `int`
5658
let eq = (x1, x2) => x1 == x2; // or more concise: let eq = (==);
59+
let cmp = compare; // default comparator from Pervasives module
5760
}
5861
```
5962

@@ -64,6 +67,7 @@ module Container = {
6467
type t; // abstract type
6568
external id: unit => t = "%identity"; // `Container.id()` would produce value of abstract type `t`
6669
let eq = (_, _) => true; // since `Container` is singleton, it's always equal to self
70+
let cmp = (_, _) => 0; // same logic applies
6771
}
6872
```
6973

@@ -73,7 +77,7 @@ For convenience, `re-dnd` exposes functor which would create such singleton for
7377
module Container = Dnd.MakeSingletonContainer();
7478
```
7579

76-
Now, when we have all configuration defined, we can create module which holds React components:
80+
Now, when we have complete configuration defined, we can create module which holds React components:
7781

7882
```reason
7983
module Items = Dnd.Make(Item, Container);
@@ -189,6 +193,7 @@ type item = int;
189193
module Item = {
190194
type t = item;
191195
let eq = (x1, x2) => x1 == x2;
196+
let cmp = compare;
192197
};
193198
194199
module Container =

docs/02-SaferIdentifiersAndMultipleContainersGuide.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,13 @@ module MakeId = () => {
222222
external make: int => t = "%identity";
223223
external toInt: t => int = "%identity";
224224
225+
let eq = (x1, x2) => x1->toInt == x2->toInt;
226+
let cmp = (x1, x2) => compare(x1->toInt, x2->toInt);
227+
225228
module Comparable =
226229
Belt.Id.MakeComparable({
227230
type t = Id.t;
228-
let cmp = Pervasives.compare;
231+
let cmp = cmp;
229232
});
230233
231234
module Map = {
@@ -248,12 +251,14 @@ With all the hard prerequisite work done, we can finally proceed to implementati
248251
```reason
249252
module DraggableItem = {
250253
type t = TodoId.t;
251-
let eq = (x1, x2) => x1->TodoId.toInt == x2->TodoId.toInt;
254+
let eq = TodoId.eq;
255+
let cmp = TodoId.cmp;
252256
};
253257
254258
module DroppableContainer = {
255259
type t = TodoListId.t;
256-
let eq = (x1, x2) => x1->TodoListId.toInt == x2->TodoListId.toInt;
260+
let eq = TodoListId.eq;
261+
let cmp = TodoListId.cmp;
257262
};
258263
259264
module Todos = Dnd.Make(DraggableItem, DroppableContainer);

docs/03-Api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module T: DndComponents = Dnd.Make(Item: DndEntry, Container: DndEntry);
99
module type DndEntry = {
1010
type t;
1111
let eq: (t, t) => bool;
12+
let cmp: (t, t) => int;
1213
};
1314
1415
module type DndComponents = {

examples/examples/CardBoard.re

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ module TodoList = {
2323
module Todos = {
2424
module Item = {
2525
type t = TodoId.t;
26-
let eq = (x1, x2) => x1->TodoId.toInt == x2->TodoId.toInt;
26+
let eq = TodoId.eq;
27+
let cmp = TodoId.cmp;
2728
};
2829

2930
module Container = {
3031
type t = TodoListId.t;
31-
let eq = (x1, x2) => x1->TodoListId.toInt == x2->TodoListId.toInt;
32+
let eq = TodoListId.eq;
33+
let cmp = TodoListId.cmp;
3234
};
3335

3436
include Dnd.Make(Item, Container);
@@ -37,7 +39,8 @@ module Todos = {
3739
module TodoLists = {
3840
module Item = {
3941
type t = TodoListId.t;
40-
let eq = (x1, x2) => x1->TodoListId.toInt == x2->TodoListId.toInt;
42+
let eq = TodoListId.eq;
43+
let cmp = TodoListId.cmp;
4144
};
4245

4346
module Container =

examples/examples/NestedVerticalLists.re

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ module TodoList = {
2323
module Todos = {
2424
module Item = {
2525
type t = TodoId.t;
26-
let eq = (x1, x2) => x1->TodoId.toInt == x2->TodoId.toInt;
26+
let eq = TodoId.eq;
27+
let cmp = TodoId.cmp;
2728
};
2829

2930
module Container = {
3031
type t = TodoListId.t;
31-
let eq = (x1, x2) => x1->TodoListId.toInt == x2->TodoListId.toInt;
32+
let eq = TodoListId.eq;
33+
let cmp = TodoListId.cmp;
3234
};
3335

3436
include Dnd.Make(Item, Container);
@@ -37,7 +39,8 @@ module Todos = {
3739
module TodoLists = {
3840
module Item = {
3941
type t = TodoListId.t;
40-
let eq = (x1, x2) => x1->TodoListId.toInt == x2->TodoListId.toInt;
42+
let eq = TodoListId.eq;
43+
let cmp = TodoListId.cmp;
4144
};
4245

4346
module Container =

examples/examples/SimpleList.re

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ module Todo = {
1111
module Todos = {
1212
module Item = {
1313
type t = TodoId.t;
14-
let eq = (x1, x2) => x1->TodoId.toInt == x2->TodoId.toInt;
14+
let eq = TodoId.eq;
15+
let cmp = TodoId.cmp;
1516
};
1617

1718
module Container =

examples/guides/GettingStartedGuide.re

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ type item = int;
22

33
module Item = {
44
type t = item;
5-
let eq = (x1, x2) => x1 == x2;
5+
let eq: (item, item) => bool = (x1, x2) => x1 == x2;
6+
let cmp: (item, item) => int = Pervasives.compare;
67
};
78

89
module Container =

0 commit comments

Comments
 (0)