Skip to content

Commit 10c60bc

Browse files
committed
# v0.1.5 process
1 parent dbe11c1 commit 10c60bc

File tree

19 files changed

+126
-84
lines changed

19 files changed

+126
-84
lines changed

CHANGELOG.md

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# Changelog
22

3+
# 0.1.5
4+
Change selector payload type of data, now it's *Immutable JSON or unndefined* please see [test-source](https://github.com/edtoken/redux-tide/blob/master/test/selector.spec.js#L48)
5+
Implement `action.delete` functionality, for details please see [source](https://github.com/edtoken/redux-tide/blob/master/src/action.js#L464) and [example](https://edtoken.github.io/redux-tide/?ex=delete-entity-from-state) and [example-source](https://github.com/edtoken/redux-tide/blob/master/website/src/delete-entity-from-state/index.js#L1)
6+
Improve documentation
7+
Improve examples, add new example
8+
Add code sandbox examples
9+
Add new badges
10+
11+
# 0.1.4
12+
13+
# 0.1.5
14+
Change selector payload type of data, now it's *Immutable JSON or unndefined* please see [test-source](https://github.com/edtoken/redux-tide/blob/master/test/selector.spec.js#L48)
15+
Implement `action.delete` functionality, for details please see [source](https://github.com/edtoken/redux-tide/blob/master/src/action.js#L464) and [example](https://edtoken.github.io/redux-tide/?ex=delete-entity-from-state) and [example-source](https://github.com/edtoken/redux-tide/blob/master/website/src/delete-entity-from-state/index.js#L1)
16+
Improve documentation
17+
Improve examples, add new example
18+
Add code sandbox examples
19+
Add new badges
20+
21+
# 0.1.4
22+
323
# 0.1.3
424
Fix critical bug in method `Action.empty`
525
small refactoring action.js, selector.js files

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ ActionCreator + ActionSelector, reducers are created automatically
2929
[![Maintainability](https://api.codeclimate.com/v1/badges/5952e9edfa038e49658f/maintainability)](https://codeclimate.com/github/edtoken/redux-tide/maintainability)
3030
[![npm downloads](https://img.shields.io/npm/dm/redux-tide.svg?style=flat-square)](https://www.npmjs.com/package/redux-tide)
3131
[![Coverage Status](https://coveralls.io/repos/github/edtoken/redux-tide/badge.svg?branch=master)](https://coveralls.io/github/edtoken/redux-tide?branch=master)
32-
[![Inline docs](https://inch-ci.org/github/edtoken/redux-tide.svg?branch=master)](https://inch-ci.org/github/edtoken/redux-tide)
32+
[![Inline docs](https://inch-ci.org/github/edtoken/redux-tide.svg?branch=master)](https://inch-ci.org/github/edtoken/redux-tide)
33+
[![dependencies Status](https://david-dm.org/edtoken/redux-tide/status.svg)](https://david-dm.org/edtoken/redux-tide)
34+
[![devDependencies Status](https://david-dm.org/edtoken/redux-tide/dev-status.svg)](https://david-dm.org/edtoken/redux-tide?type=dev)
3335
[![HitCount](http://hits.dwyl.com/edtoken/redux-tide.svg)](http://hits.dwyl.com/edtoken/redux-tide)
3436

3537
[![NPM](https://nodei.co/npm/redux-tide.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/redux-tide/)

lib/selector.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@ var getPayloadIds = function getPayloadIds(dataKey, isArray, actionState, stateK
4444
};
4545

4646
var makeActionDenormalizedPayload = function makeActionDenormalizedPayload(isArray, payloadIds, schema, entities) {
47+
// return empty immutable object
4748
if (!payloadIds) {
4849
return undefined;
4950
}
5051

5152
var result = (0, _helper.denormalize)(payloadIds, [schema], entities).filter(function (v) {
5253
return v;
53-
}).map(function (item) {
54-
return item.toJS();
5554
});
55+
5656
return isArray ? result : result[0];
5757
};
5858

5959
var makeActionDenormalizedPayloads = function makeActionDenormalizedPayloads(isFetching, actionSchema, entities, payloadIsArray, actionDataKey, entityState, actionState) {
6060
if (!actionDataKey) {
61-
return {};
61+
return undefined;
6262
}
6363

6464
if (!entityState) {
@@ -133,7 +133,10 @@ var getMergedActionsData = exports.getMergedActionsData = function getMergedActi
133133
});
134134

135135
return sortedByUpate.reduce(function (memo, item) {
136-
return Object.assign(memo, item);
136+
return Object.assign(memo, item, {
137+
payload: memo.payload ? memo.payload.merge(item.payload) : item.payload,
138+
prevPayload: memo.prevPayload ? memo.prevPayload.merge(item.prevPayload) : item.prevPayload
139+
});
137140
});
138141
});
139142
};

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "redux-tide",
33
"description": "tiny factory for redux crud normalize",
4-
"version": "0.1.3",
4+
"version": "0.1.5",
55
"main": "./lib/index.js",
66
"files": [
77
"lib",
@@ -82,7 +82,7 @@
8282
"jsdoc": "^3.5.5",
8383
"json-server": "^0.12.1",
8484
"minami": "^1.2.3",
85-
"mocha": "^4.1.0",
85+
"mocha": "^5.0.0",
8686
"prettier": "^1.9.2",
8787
"raw-loader": "^0.5.1",
8888
"react": "^16.2.0",

src/selector.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ const makeActionDenormalizedPayload = (
4646
schema,
4747
entities
4848
) => {
49+
// return empty immutable object
4950
if (!payloadIds) {
5051
return undefined
5152
}
5253

53-
const result = denormalize(payloadIds, [schema], entities)
54-
.filter(v => v)
55-
.map(item => item.toJS())
54+
const result = denormalize(payloadIds, [schema], entities).filter(v => v)
55+
5656
return isArray ? result : result[0]
5757
}
5858

@@ -66,7 +66,7 @@ const makeActionDenormalizedPayloads = (
6666
actionState
6767
) => {
6868
if (!actionDataKey) {
69-
return {}
69+
return undefined
7070
}
7171

7272
if (!entityState) {
@@ -168,7 +168,14 @@ export const getMergedActionsData = (...actions) => {
168168
const sortedByUpate = actionsData.sort((a, b) => a.time - b.time)
169169

170170
return sortedByUpate.reduce((memo, item) => {
171-
return Object.assign(memo, item)
171+
return Object.assign(memo, item, {
172+
payload: memo.payload
173+
? memo.payload.merge(item.payload)
174+
: item.payload,
175+
prevPayload: memo.prevPayload
176+
? memo.prevPayload.merge(item.prevPayload)
177+
: item.prevPayload
178+
})
172179
})
173180
}
174181
)

test/selector.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ it('selector getActionData', function() {
4646
}
4747

4848
const result = getActionData(action)(state)
49+
result.payload = result.payload.toJS()
4950

5051
result.should.be.deepEqual({
5152
status: '',

website/public/index.html

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4+
<!-- Global site tag (gtag.js) - Google Analytics -->
5+
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-113081893-1"></script>
6+
<script>
7+
window.dataLayer = window.dataLayer || [];
8+
function gtag(){dataLayer.push(arguments);}
9+
gtag('js', new Date());
10+
11+
gtag('config', 'UA-113081893-1');
12+
</script>
13+
14+
415
<meta charset="utf-8">
516
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
617
<meta name="theme-color" content="#000000">

website/src/blog/actions.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {postsSchema} from "./schema"
77
*
88
* @type {Action}
99
*/
10-
export const getAllPost = createAction(postsSchema, api.get, query => [`posts`, query])
10+
export const getAllPost = createAction(postsSchema, api.get, query => [`posts?_embed=comments`, query])
1111

1212

1313
/**
@@ -17,10 +17,10 @@ export const getAllPost = createAction(postsSchema, api.get, query => [`posts`,
1717
*
1818
* @type {Action}
1919
*/
20-
export const fetchPost = createAction(postsSchema, api.get, postId => `posts/${postId}`)
20+
export const fetchPost = createAction(postsSchema, api.get, postId => `posts/${postId}?_embed=comments`)
2121

2222
export const updatePost = createAction(postsSchema, api.put, (postId, data) => [
23-
`posts/${postId}`,
23+
`posts/${postId}?_embed=comments`,
2424
undefined,
2525
data
2626
])

website/src/blog/index.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class BlogPostFormComponent extends Component {
3939
// return
4040
// }
4141

42-
this.setState({form: this.props.payload || {}})
42+
this.setState({form: this.props.payload ? this.props.payload.toJS() : {}})
4343
}
4444

4545
componentWillMount() {
@@ -67,6 +67,8 @@ class BlogPostFormComponent extends Component {
6767
const disableEdit = isFetching
6868
const completed = saved && this.props.status === 'success'
6969

70+
console.log('payload', payload)
71+
7072
return (<div className="static-modal">
7173
<Modal show={true} onHide={this.props.onHide}>
7274
<Modal.Header closeButton>
@@ -88,9 +90,6 @@ class BlogPostFormComponent extends Component {
8890
But you are calling only <b>PUT post/postId</b>
8991
</Alert>
9092

91-
<h3>fetchPost payload:</h3>
92-
<pre><code>{JSON.stringify(payload, null, 2)}</code></pre>
93-
9493
{isFetching && <div>
9594
<Spinner/>
9695
</div>}
@@ -125,6 +124,11 @@ class BlogPostFormComponent extends Component {
125124
{!completed && 'Save changes'}
126125
</Button>
127126
</Modal.Footer>
127+
128+
<div className="container-fluid">
129+
<h3>fetchPost payload:</h3>
130+
<pre><code>{JSON.stringify(payload, null, 2)}</code></pre>
131+
</div>
128132
</Modal>
129133
</div>
130134
)
@@ -212,11 +216,11 @@ class BlogPostsTableComponent extends Component {
212216

213217
{hasPayload && payload.map((item, num) => {
214218
return <tr
215-
key={['table-post', item.id, num].join('-')}
216-
onClick={() => this.props.handleOpenPost(item.id)}>
217-
<td>{item.userId}</td>
218-
<td>{item.id}</td>
219-
<td>{item.title}</td>
219+
key={['table-post', item.get('id'), num].join('-')}
220+
onClick={() => this.props.handleOpenPost(item.get('id'))}>
221+
<td>{item.get('userId')}</td>
222+
<td>{item.get('id')}</td>
223+
<td>{item.get('title')}</td>
220224
<td>
221225

222226
</td>
@@ -283,8 +287,15 @@ class BlogExampleComponent extends Component {
283287

284288
return (<div>
285289
<h1>Blog Example</h1>
286-
<p>Source code <a href="https://github.com/edtoken/redux-tide/tree/master/website/src/blog"
287-
target='_blank'>source</a></p>
290+
<p>
291+
Preview in SandBox&nbsp;<a
292+
href='https://codesandbox.io/s/github/edtoken/redux-tide/tree/master/website?module=/src/blog/index.js&moduleview=1'
293+
target='_blank'>codesandbox.io</a>
294+
</p>
295+
296+
<p>Source code&nbsp;<a
297+
href='https://github.com/edtoken/redux-tide/tree/master/website/src/blog'
298+
target='_blank'>source</a></p>
288299

289300
<Alert bsStyle="info">
290301
Demonstrate how to create list and single item requests, sync data between it, witout reducers

website/src/blog/schema.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ const commentsSchema = new schema.Entity('comments')
55
const postsSchema = new schema.Entity('posts')
66

77
postsSchema.define({
8-
// author: profileSchema,
9-
// comments: [commentsSchema]
8+
author: profileSchema,
9+
comments: [commentsSchema]
1010
})
1111

1212
commentsSchema.define({
13-
// postId: postsSchema
13+
postId: postsSchema
1414
})
1515

1616
export {

website/src/delete-entity-from-state/actions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import {postsSchema} from "./schema"
1313
export const fetchPost = createAction(
1414
postsSchema,
1515
api.get,
16-
postId => `posts/${postId}`
16+
postId => `posts/${postId}?_embed=comments`
1717
)
1818

1919
export const updatePost = createAction(
2020
postsSchema,
2121
api.put,
2222
(postId, data) => [
23-
`posts/${postId}`,
23+
`posts/${postId}?_embed=comments`,
2424
undefined,
2525
data
2626
]

website/src/delete-entity-from-state/index.js

+10-36
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ class CommonPostComponent extends Component {
5656
<br/>
5757
<br/>
5858
{hasError && <div className="alert alert-danger">{errorText}</div>}
59-
<pre>{JSON.stringify(payload, null, 2)}</pre>
59+
<pre>{JSON.stringify({
60+
title: payload ? payload.get('title') : ''
61+
}, null, 2)}</pre>
6062
</div>)
6163
}
6264
}
@@ -74,33 +76,6 @@ const CommonPost = connect(
7476
})
7577
)(CommonPostComponent)
7678

77-
class PostsListComponent extends Component {
78-
79-
render() {
80-
return (<div>
81-
<h4>Posts List</h4>
82-
</div>)
83-
}
84-
}
85-
86-
const PostsList = connect(
87-
(state, props) => ({}),
88-
(dispatch) => ({})
89-
)(PostsListComponent)
90-
91-
class PostsTableComponent extends Component {
92-
render() {
93-
return (<div>
94-
<h4>Posts Table</h4>
95-
</div>)
96-
}
97-
}
98-
99-
const PostsTable = connect(
100-
(state, props) => ({}),
101-
(dispatch) => ({})
102-
)(PostsTableComponent)
103-
10479
class DeleteTntityFromStateExampleComponent extends Component {
10580

10681
constructor(props) {
@@ -111,6 +86,13 @@ class DeleteTntityFromStateExampleComponent extends Component {
11186

11287
return (<div>
11388
<h1>Delete Entity from state</h1>
89+
90+
<p>
91+
Preview in SandBox&nbsp;<a
92+
href='https://codesandbox.io/s/github/edtoken/redux-tide/tree/master/website?module=/src/delete-entity-from-state/index.js&moduleview=1'
93+
target='_blank'>codesandbox.io</a>
94+
</p>
95+
11496
<p>Source code <a
11597
href="https://github.com/edtoken/redux-tide/tree/master/website/src/delete-entity-from-state"
11698
target='_blank'>source</a>
@@ -124,18 +106,10 @@ class DeleteTntityFromStateExampleComponent extends Component {
124106
<div className="col-md-6">
125107
<h1>With delete <small className='text-success'>It's correct</small></h1>
126108
<CommonPost postId={1}/>
127-
<hr/>
128-
<PostsTable isCorrect/>
129-
<hr/>
130-
<PostsList isCorrect/>
131109
</div>
132110
<div className="col-md-6">
133111
<h1>Without delete <small className='text-danger'>It's no correct</small></h1>
134112
<CommonPost postId={1}/>
135-
<hr/>
136-
<PostsTable/>
137-
<hr/>
138-
<PostsList/>
139113
</div>
140114
</div>
141115
</div>)

website/src/delete-entity-from-state/schema.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ const commentsSchema = new schema.Entity('comments')
55
const postsSchema = new schema.Entity('posts')
66

77
postsSchema.define({
8-
// author: profileSchema,
9-
// comments: [commentsSchema]
8+
author: profileSchema,
9+
comments: [commentsSchema]
1010
})
1111

1212
commentsSchema.define({
13-
// postId: postsSchema
13+
postId: postsSchema
1414
})
1515

1616
export {

0 commit comments

Comments
 (0)