Skip to content

Commit

Permalink
Merge branch 'release/1.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
vankeisb committed Oct 19, 2020
2 parents 80e02fe + edcb33c commit 136c458
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 6 deletions.
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
# Changelog

## v1.1.0 (01/10/2020)
## v1.1.1 (01/10/2020)

#### closed

- [**closed**] upgrade react-scripts in samples [#29](https://github.com/vankeisb/react-tea-cup/pull/29)

---

## v1.1.0 (01/10/2020)
- [**closed**] Do not rely on state in Program [#25](https://github.com/vankeisb/react-tea-cup/pull/25)
- [**closed**] fix #26 : use componentWillUnmount instead of componentWillMount [#28](https://github.com/vankeisb/react-tea-cup/pull/28)
- [**closed**] dispatch initial cmd on mount [#23](https://github.com/vankeisb/react-tea-cup/pull/23)

---

## v1.0.1 (01/10/2020)

---

## v1.0.2 (01/10/2020)

---

## v1.0.0 (01/10/2020)
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tea-cup-core",
"version": "1.1.1",
"version": "1.1.2",
"description": "react-tea-cup core classes and utilities (Maybe etc)",
"author": "Rémi Van Keisbelck <[email protected]>",
"license": "MIT",
Expand Down
32 changes: 32 additions & 0 deletions core/src/TeaCup/Decode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,35 @@ test('oneOf', () => {
test('from string', () => {
expect(num.decodeString('123')).toEqual(ok(123));
});

test('any value', () => {
const anyValue = { foo: 'bar' };
expect(Decode.value.decodeValue(anyValue)).toEqual(ok(anyValue));
});

describe('optional field', () => {
test("is present", () => {
const value = { foo: 'bar', gnu: 13 };
expect(Decode.optionalField('gnu', Decode.num).decodeValue(value)).toEqual(ok(13));
})
test("is missing", () => {
const value = { foo: 'bar' };
expect(Decode.optionalField('gnu', Decode.num).decodeValue(value)).toEqual(ok(undefined));
})

test("typical use case", () => {
type MyType = {
foo: string;
gnu?: number;
}
const value = { foo: 'bar' };
const expected: MyType = {
foo: 'bar'
};
expect(Decode.map2(
(foo, gnu) => { return { foo, gnu } },
Decode.field('foo', Decode.str),
Decode.optionalField('gnu', Decode.num)).decodeValue(value)
).toEqual(ok(expected));
})
});
14 changes: 13 additions & 1 deletion core/src/TeaCup/Decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ export class Decode {
return Decode.at([key], d);
}

/**
* Decoder for optinal object fields
* @param key the name of the optinal field
* @param d the decoder for the field's value
*/
static optionalField<T>(key: string, d: Decoder<T>): Decoder<T | undefined> {
return Decode.andThen(
(value) => value.map<Decoder<T | undefined>>(v => new Decoder<T>(() => d.decodeValue(v))).withDefault(Decode.succeed(undefined)),
Decode.maybe(Decode.field(key, Decode.value))
);
}

/**
* Decoder for navigable object properties
* @param keys a list of fields to navigate
Expand Down Expand Up @@ -439,7 +451,7 @@ export class Decode {
/**
* Decoder for any value
*/
static value: Decoder<any> = new Decoder<any>((o) => o);
static value: Decoder<any> = new Decoder<any>((o) => ok(o));

/**
* Decoder for null
Expand Down
2 changes: 1 addition & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-scripts": "3.4.3",
"react-tea-cup": "1.1.1"
"react-tea-cup": "1.1.2"
},
"scripts": {
"start": "react-scripts start",
Expand Down
4 changes: 2 additions & 2 deletions tea-cup/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-tea-cup",
"version": "1.1.1",
"version": "1.1.2",
"description": "Put some TEA in your React.",
"author": "Rémi Van Keisbelck <[email protected]>",
"license": "MIT",
Expand All @@ -19,7 +19,7 @@
"samples": "tsc --outFile ./dist/Samples/index.js && cp ./src/Samples/index.html ./dist/Samples"
},
"dependencies": {
"tea-cup-core": "1.1.1",
"tea-cup-core": "1.1.2",
"react": "^16.7.0"
},
"devDependencies": {
Expand Down

0 comments on commit 136c458

Please sign in to comment.