resolve-module-comments

Usage
import { merge } from 'resolve-scripts'
import createModuleComments from 'resolve-module-comments'
merge(
resolveConfig,
createModuleComments()
)
Customization of module options
import { merge } from 'resolve-scripts'
import createModuleComments from 'resolve-module-comments'
merge(
resolveConfig,
createModuleComments({
aggregateName: 'CustomCommentsAggregateName', // default = 'Comments'
readModelName: 'CustomCommentsReadModelName', // default = 'Comments'
readModelConnector: {
module: 'CustomreadModelConnector', // default = resolve-readmodel-lite'
options: {} // default = {}
},
commentsTableName: 'CustomCommentsTableName', // default = 'Comments'
reducerName: 'CustomReducerName', // default = 'comments'
eventTypes: {
COMMENT_CREATED: 'CUSTOM_COMMENT_CREATED', // default = 'COMMENT_CREATED'
COMMENT_UPDATED: 'CUSTOM_COMMENT_UPDATED', // default = 'COMMENT_UPDATED'
COMMENT_REMOVED: 'CUSTOM_COMMENT_REMOVED' // default = 'COMMENT_REMOVED'
},
commandTypes: {
createComment: 'customCreateComment', // default = 'createComment'
updateComment: 'customUpdateComment', // default = 'updateComment'
removeComment: 'customRemoveComment', // default = 'removeComment'
},
resolverNames: {
commentsTree: 'customCommentsTree', // default = 'commentsTree',
foreignCommentsCount: 'customForeignCommentsCount', // default = 'foreignCommentsCount',
allCommentsPaginate: 'customAllCommentsPaginate', // default = 'allCommentsPaginate'
},
maxNestedLevel: 2, // default = undefined
verifyCommand: path.join(__dirname, 'customVerifyCommand.js') // default = 'resolve-module-comments/lib/aggregates/verify-command.js'
})
)
Customization of verifyCommand
// customVerifyCommand.js
const verifyCommand = async (state, command, jwt) => {
// ...
}
export default verifyCommand

Commands
createComment(aggregateId, {
authorId,
commentId
parentCommentId,
content
})
updateComment(aggregateId, {
authorId,
commentId
content
})
removeComment(aggregateId, {
authorId,
commentId
})
Renderless Connectors
import React from 'react'
import {
CommentsTreeRenderless,
CommentsPaginateRenderless,
CommentsNotificationRenderless,
RefreshHelperRenderless
} from 'resolve-module-comments'
export const CommentsTree = (props) =>
<CommentsTreeRenderless
treeId="treeId"
parentCommentId="parentCommentId"
authorId="authorId"
>
{({ comments, createComment, renameComment, removeComment }) => {
// eslint-disable-next-line
console.log('comments:', comments)
return null
}}
</CommentsTreeRenderless>
export const CommentsPaginate = ({ itemsOnPage }) =>
<CommentsPaginateRenderless
itemsOnPage
pageNumber
readModelName="customReadModelName" // default = 'readModelName'
resolverName="customAllCommentsPaginate" // default = 'allCommentsPaginate'
>
{({ pageNumber, comments }) => {
// eslint-disable-next-line
console.log(
`comments (pageNumber: ${pageNumber}, itemsOnPage: ${itemsOnPage}):`,
comments
)
return null
}}
</CommentsPaginateRenderless>
export const CommentsNotification = (props) =>
<CommentsNotificationRenderless
treeId="treeId"
parentCommentId="parentCommentId"
authorId="authorId"
readModelName="customReadModelName" // default = 'readModelName'
resolverName="customResolverName" // default = 'foreignCommentsCount'
{...props}
>
{({ count, onClick }) => {
if(count === 0) return null
return (
<div onClick={onClick}>
Comments had been updated - refresh page to see them
</div>
)
}}
</CommentsNotificationRenderless>
export const RefreshHelper = () =>
<RefreshHelperRenderless>
{({ refreshId, refresh }) => (
<div onClick={refresh}>
{refreshId}
</div>
)}
</RefreshHelperRenderless>