Skip to content

Commit

Permalink
comics feature is now xkcd feature (related to #44)
Browse files Browse the repository at this point in the history
  • Loading branch information
icmx committed May 4, 2021
1 parent 4f6b4d9 commit aaaf638
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import Core from '~/app/core';
import random from '~/app/utils/random';

class ComicApi extends Core.Api {
/**
* Xkcd API client.
*/
class XkcdApi extends Core.Api {
constructor(endpoint) {
super(endpoint);
}

/**
* Get specific xkcd comic by its id (`num` property). If `num` is
* omitted, then latest comic will be returned.
* Get specific xkcd comic JSON data by its id (`num` property). If
* `num` is omitted, then current (latest) comic will be retrieved.
* @param {number} num - xkcd comic id to get
* @returns XkcdComic
*/
async get(num) {
this.refresh();
Expand All @@ -31,7 +36,8 @@ class ComicApi extends Core.Api {
}

/**
* Get current (latest) xkcd comic.
* Get current (i.e. latest) xkcd comic.
* @returns XkcdComic
*/
async current() {
try {
Expand All @@ -43,8 +49,9 @@ class ComicApi extends Core.Api {

/**
* Get random xkcd comic.
* Note: due to official JSON API design, this will perform two
* actual API requests.
* *Note:* due to official JSON API design, this method will perform
* two actual HTTP requests.
* @returns XkcdComic
*/
async random() {
try {
Expand All @@ -61,4 +68,4 @@ class ComicApi extends Core.Api {
}
}

export default ComicApi;
export default XkcdApi;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Core from '~/app/core';

class ComicController extends Core.Controller {
class XkcdController extends Core.Controller {
constructor({ model, view }) {
super({ model, view });
}
Expand All @@ -16,4 +16,4 @@ class ComicController extends Core.Controller {
}
}

export default ComicController;
export default XkcdController;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Core from '~/app/core';

class ComicModel extends Core.Model {
class XkcdModel extends Core.Model {
#api;

constructor(api) {
Expand Down Expand Up @@ -51,4 +51,4 @@ class ComicModel extends Core.Model {
}
}

export default ComicModel;
export default XkcdModel;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Core from '~/app/core';
import int from '~/app/utils/int';
import isInt from '~/app/utils/isInt';

class ComicView extends Core.View {
class XkcdView extends Core.View {
#navbarButtons;

#firstButton;
Expand Down Expand Up @@ -248,4 +248,4 @@ class ComicView extends Core.View {
}
}

export default ComicView;
export default XkcdView;
14 changes: 7 additions & 7 deletions src/app/features/comics/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ComicModel from './ComicModel';
import ComicView from './ComicView';
import ComicController from './ComicController';
import XkcdModel from './XkcdModel';
import XkcdView from './XkcdView';
import XkcdController from './XkcdController';

import ComicApi from './ComicApi';
import XkcdApi from './XkcdApi';

const comics = new ComicController({
model: new ComicModel(new ComicApi('/api/comics')),
view: new ComicView(window.document.querySelector('.xv-app')),
const comics = new XkcdController({
model: new XkcdModel(new XkcdApi('/api/comics')),
view: new XkcdView(window.document.querySelector('.xv-app')),
});

export default comics;

0 comments on commit aaaf638

Please sign in to comment.