# @resolve-js/module-comments

> A reSolve module that allows an application's users to post comments.

Latest version **0.34.3** (published 2022-07-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @resolve-js/module-comments
pnpm add @resolve-js/module-comments
yarn add @resolve-js/module-comments
bun add @resolve-js/module-comments
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.34.3 |
| Published | 2022-07-29 |
| First published | 2021-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=14.17 |
| Dependencies | 1 |
| Unpacked size | 123.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 769 |
| Author | reimagined team |
| Maintainers | resolve-admin |
| Keywords | cqrs, eventsourcing, es, ddd |

## Links

- npm: https://www.npmjs.com/package/@resolve-js/module-comments
- Repository: https://github.com/reimagined/resolve
- Homepage: https://github.com/reimagined/resolve/tree/master/packages/modules/@resolve-js/module-comments#readme
- Issues: https://github.com/reimagined/resolve/issues
- npm.io page: https://npm.io/package/@resolve-js/module-comments

## Dependencies (1)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) 7.17.2

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 0.34.3 (latest) — 2022-07-29
- 0.28.1-alpha (pre-release) — 2021-03-10
- 0.34.2 — 2022-04-19
- 0.34.1 — 2022-04-18
- 0.34.0 — 2022-04-11
- 0.33.15 — 2022-03-03
- 0.33.14 — 2022-01-27
- 0.33.13 — 2022-01-24
- 0.33.12 — 2022-01-21
- 0.33.11 — 2022-01-20
- 0.33.10 — 2022-01-17
- 0.33.9 — 2022-01-12
- 0.33.8 — 2021-12-29
- 0.33.7 — 2021-12-20
- 0.33.6 — 2021-12-02
- … 28 more at https://npm.io/package/@resolve-js/module-comments/versions

## README

# **@resolve-js/module-comments**

[![npm version](https://badge.fury.io/js/%40resolve-js%2Fmodule-comments.svg)](https://badge.fury.io/js/%40resolve-js%2Fmodule-comments)

## Usage

```js
import { merge } from '@resolve-js/scripts'
import createModuleComments from '@resolve-js/module-comments'

merge(resolveConfig, createModuleComments())
```

#### Customization of module options

```js
import { merge } from '@resolve-js/scripts'
import createModuleComments from '@resolve-js/module-comments'

merge(
  resolveConfig,
  createModuleComments({
    aggregateName: 'CustomCommentsAggregateName', // default = 'Comments'
    readModelName: 'CustomCommentsReadModelName', // default = 'Comments'
    readModelConnector: {
      module: 'CustomreadModelConnector', // default = @resolve-js/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-js/module-comments/lib/aggregates/verify-command.js'
  })
)
```

#### Customization of verifyCommand

```js
// customVerifyCommand.js

const verifyCommand = async (state, command, jwt) => {
  // ...
}

export default verifyCommand
```

![Analytics](https://ga-beacon.appspot.com/UA-118635726-1/packages-@resolve-js/module-comments-readme?pixel)

#### Commands

```js
createComment(aggregateId, {
  authorId,
  commentId,
  parentCommentId,
  content,
})

updateComment(aggregateId, {
  authorId,
  commentId,
  content,
})

removeComment(aggregateId, {
  authorId,
  commentId,
})
```

#### Renderless Connectors

```js
import React from 'react'

import {
  CommentsTreeRenderless,
  CommentsPaginateRenderless,
  CommentsNotificationRenderless,
  RefreshHelperRenderless,
} from '@resolve-js/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 have been updated - refresh page to see them
        </div>
      )
    }}
  </CommentsNotificationRenderless>
)

export const RefreshHelper = () => (
  <RefreshHelperRenderless>
    {({ refreshId, refresh }) => <div onClick={refresh}>{refreshId}</div>}
  </RefreshHelperRenderless>
)
```

---
_Source: https://npm.io/package/@resolve-js/module-comments · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
