Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: sketching out idea in examples #140

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ Matching `fetch()` responses:
```javascript
const res = await fetch(jsonService)
case (res) {
when {status: 200, headers: {'Content-Length': s}} ->
let {status: 200, headers: {'Content-Length': s}} ->
console.log(`size is ${s}`),
when {status: 404} -> {
let {status: 404} -> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let {status: 404} -> {
let {status: 404} ->

I think this { is a left over right?

console.log('JSON not found'),
when {status} if (status >= 400) -> {
let {status} if (status >= 400) -> {
throw new RequestError(res)
},
}
Expand All @@ -59,11 +59,11 @@ documentation](https://redux.js.org/basics/reducers#splitting-reducers):
```js
function todoApp (state = initialState, action) {
return case (action) {
when {type: 'set-visibility-filter', filter: visFilter} ->
let {type: 'set-visibility-filter', filter: visFilter} ->
({...state, visFilter}),
when {type: 'add-todo', text} ->
let {type: 'add-todo', text} ->
({...state, todos: [...state.todos, {text}]}),
when {type: 'toggle-todo', index} -> (
let {type: 'toggle-todo', index} -> (
{
...state,
todos: state.todos.map((todo, idx) => idx === index
Expand All @@ -72,7 +72,7 @@ function todoApp (state = initialState, action) {
)
}
)
when _ -> state // ignore unknown actions
let _ -> state // ignore unknown actions
}
}
```
Expand All @@ -83,9 +83,9 @@ version:
```js
<Fetch url={API_URL}>{
props => case (props) {
when {loading} -> <Loading />
when {error} -> <Error error={error} />
when {data} -> <Page data={data} />
let {loading} -> <Loading />
let {error} -> <Error error={error} />
let {data} -> <Page data={data} />
}
}
</Fetch>
Expand All @@ -96,9 +96,9 @@ General structural duck-typing on an API for vector-likes.

```js
const getLength = vector => case (vector) {
when { x, y, z } -> Math.sqrt(x ** 2 + y ** 2 + z ** 2)
when { x, y } -> Math.sqrt(x ** 2 + y ** 2)
when [...etc] -> vector.length
const { x, y, z } -> Math.sqrt(x ** 2 + y ** 2 + z ** 2)
const { x, y } -> Math.sqrt(x ** 2 + y ** 2)
const [...etc] -> vector.length
}
getLength({x: 1, y: 2, z: 3}) // 3.74165
```
Expand Down