2.0.0 • Published 4 years ago

@vendasta/codex v2.0.0

Weekly downloads
14
License
ISC
Repository
-
Last release
4 years ago

codex SDK

The Codex deals with two main concepts: Questions and Answers. There are two services for dealing with these concepts, the ListQuestionsService and the QuestionService.

QuestionService

This one is straight forward, just inject an instance and use it as needed. It has the following capabilities:

  • getQuestion - get a question by its id
  • getComments - return a list of comments for a question id
  • commentOnQuestion - make a comment on a question
  • createQuestion - create a question in the Codex and get its id back for future use.
  • markCommentAsAnswer - mark a comment on a question as the answer to it
  • markCommentAsStale - mark a comment on a question as "stale", this will also unmark it as the answer.
  • deleteQuestion - delete a question by its id

ListQuestionsService

When you are dealing with listing and loading multiple questions at once, it's time for the ListQuestionsService. It exposes some observables that your component can mirror:

  • questions$ - the list of questions that has been retrieved over the life of the service, i.e. this will update if you load more questions
  • hasMore$ - an observable boolean that will let you know if there are still more results
  • nextCursor$ - an observable string that you can use to load more questions
  • loading$ - an observable boolean that should indicate whether an api request is currently being made.
  • totalResults$ - an observable int that has the total results of the list api

Using this service might look something like this. Here's an example component using this service:

import { ListQuestionsService } from './lib/';

class MyComponent {
  loading$ = this.listQuestions.loading$;
  questions$ = this.listQuestions.questions$;
  hasMore$ = this.listQuestions.hasMore$;
  nextCursor$ = this.listQuestions.nextCursor$;
  totalResults$ = this.listQuestions.totalResults$;

  constructor(private listQuestions: ListQuestionsService) {}

  ngOnInit() {
    // Set a custom page size first.
    this.listQuestions.pageSize = 20;
    this.listQuestions.loadQuestions();
  }
}

That's it. You'll be able to show a Load More type of button or do infinite scroll, whichever you prefer. The easiest way to get the cursor to the loadMoreQuestions function is to subscribe to it in your component and pass it on each click of the load more button or what have you. You can specify the size of each page by setting that on the service, like in the example above.

2.0.0

4 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.2.0

6 years ago

1.3.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.1

6 years ago