1.0.5 • Published 3 years ago

octomments v1.0.5

Weekly downloads
310
License
MIT
Repository
github
Last release
3 years ago

Octomments client

The core functionality of Octomments.

Setup

<script src="https://unpkg.com/octomments/build/ocs.min.js"></script>

or

> npm i octomments

Usage

import Octomments from 'octomments';

function Renderer(api, container) {
  api.on(Octomments.USER_NONE, (loginURL) => {
    console.log(loginURL);
  });
}

const octomments = Octomments({
  github: {
    owner: '<username>',
    repo: '<repo name>',
  },
  issueNumber: <issue number>,
  renderer: [Renderer, '<selector>']
});

octomments.init();

Options

  • github (required) - object containing owner (GitHub username) and repo (GitHub repository) fields.
  • issueNumber (required) - the number of an existing in the repository issue
  • renderer (required) - an array where the first element is a renderer function and the second one is a valid DOM element selector.
  • debug (optional) - a boolean. If true the library will print each of the dispatched events.
  • endpoints (optional) - an object with issue and token fields. The values of these fields are valid URLs pointing to Octomments server endpoints. You'll probably never need to setup those unless you deploy your own server. The already existing one is at ocs.now.sh.

Methods

api.init()

Initiates the comments and user fetching.

api.add(text)

Adding of a new comment where text is the markdown of the comment.

api.on(event, callback)

  • event - event type
  • callback - function called when the event is triggered

Here is a table with all the possible events:

eventcallback paramsdescription
Octomments.ERRORerrortype of errorwhen there is an error. Check the errors section below to see the possible types.
Octomments.COMMENTS_LOADINGnonewhen the loading of the comments begins
Octomments.COMMENTS_LOADEDcommentspagination infowhen the comments are loaded
Octomments.COMMENT_SAVINGnonewhen the user submits a comment
Octomments.COMMENT_SAVEDan array with one item - the new commentwhen the comment is saved successfully
Octomments.USER_LOADINGnonewhen the library initiates a request for the user's data
Octomments.USER_NONEuser login urlwhen there is no user logged in. Use this event to render a "log in" link.
Octomments.USER_LOADEDuser's datafirst timewhen the data of the user is fetched successfully. The second parameter shows if the user is just logged in or his/her data is pulled from the local storage

api.logout(refresh = true)

Removes the user's data from the localStorage and (potentially) refreshes the page.

api.page(index)

Initiating a new comments fetching for a page with specific index.

api.generateNewCommentURL()

Returns a URL which you can use to make the user log in. It will redirect the user to ocs.now.sh/GitHub for authentication and then back to your page.

api.off()

Removes all the listeners added with api.on.

Errors

  • 1 - comments: issue doesn't exists
  • 2 - comments: other problem loading the issue
  • 3 - comments: issue request succeed but can't parse the json response
  • 4 - comments: hit the V3 rate limit
  • 5 - user: corrupted data in local storage
  • 6 - user: can't get the access token
  • 7 - user: problem parsing the access token response
  • 8 - new comment: adding new comment failed
  • 9 - new comment: not authorized
  • 10 - new comment: request succeed but can't parse the json response
1.0.5

3 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

0.3.25

4 years ago

0.3.24

4 years ago

0.3.23

4 years ago

0.3.22

4 years ago

0.3.21

4 years ago

0.3.20

4 years ago

0.3.19

4 years ago

0.3.18

4 years ago

0.3.17

4 years ago

0.3.16

4 years ago

0.3.15

4 years ago

0.3.14

4 years ago

0.3.13

4 years ago

0.3.12

4 years ago

0.3.11

4 years ago

0.3.10

4 years ago

0.3.9

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.1

4 years ago

0.2.22

4 years ago

0.2.20

4 years ago

0.2.19

4 years ago

0.2.18

4 years ago

0.2.17

4 years ago

0.2.16

4 years ago

0.2.15

4 years ago

0.2.14

4 years ago

0.2.13

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.4

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago