Home Reference Source
import Comment from '~/models/Comment.js'
public class | source

Comment

Represents a comment

Static Method Summary

Static Public Methods
public static

fromJSON(json: Object, assembleParents: boolean): Answer

Unwraps from an API JSON object.

Constructor Summary

Public Constructor
public

Creates a new comment

Member Summary

Public Members
public

false means they are children but not listed

public
public
public
public
public
public
public

Method Summary

Public Methods
public

Converts to JSON object.

Static Public Methods

public static fromJSON(json: Object, assembleParents: boolean): Answer source

Unwraps from an API JSON object.

Params:

NameTypeAttributeDescription
json Object

User JSON object.

assembleParents boolean
  • optional
  • default: false
  • nullable: true

If the comment model does not have cyclic parent <-> childs this can be linked here

Return:

Answer (nullable: true)

object if succesful, null if unauthorized.

Throw:

TypeError

if invalid JSON object

Public Constructors

public constructor() source

Creates a new comment

Params:

NameTypeAttributeDescription
options.id number

the comment id

options.text string

comment body

options.type string

answer or post

options.sourceId number

ID of the type (e.g. the answer id or post id)

options.parent Comment

parent comment object

options.date Date

JavaScript date object representing creation time

options.owner User

The owner of the comment

options.children Array

The child comments

Public Members

public children: Comment[] source

false means they are children but not listed

public date: Date source

public id: number source

public owner: User source

public parent: Comment source

public sourceId: number source

public text: string source

public type: string source

Public Methods

public toJSON(): Object source

Converts to JSON object. NOTE: parent is null because we can't have a circular JSON. You may want to implement something like assembleParents as Comment#fromJSON does.

Return:

Object

JSON object