Home Manual Reference Source
public class | source

ResourceBase

Expression Extends:

class ResourceBase extends mix(null, Injectable)

Resource base

Static Member Summary

Static Public Members
public static get

Returns if the resource is readonly

public static get abstract

Resource name

public static get

Resource path template

public static get

Returns the url key of the resource

Static Protected Members
protected static get

Protected read-only fields

Constructor Summary

Public Constructor
public

constructor(api: Maps4News, data: Object<String, *>)

Member Summary

Public Members
public get

Get api instance

public set

api(value: Maps4News)

Set the api instance

public get

Auto generated Resource base url

public get

List fields that contain object data

public get

If the resource can be owned by an organisation

public get

url: string: *

Auto generated resource url

Method Summary

Public Methods
public

Clone the object

public

async refresh(updateSelf: Boolean): Promise<ResourceBase>

Refresh the resource by requesting it from the server again

public

reset(fields: Array<string> | string | null)

Resets model instance to it's original state

public

Clean up instance and commit all changes locally.

public

static(Target: string | function, Constructor: function, seedData: Object<string, *>): SimpleResourceProxy

Static proxy generation

public

toObject(camelCaseKeys: boolean): {}

Transform instance to object

public

String representation of the resource, similar to Python's repr

Protected Methods
protected

Macro for resource listing

protected

Moves new fields to this._properties and turns them into a getter/setter

Static Public Members

public static get readonly: boolean: boolean source

Returns if the resource is readonly

Return:

boolean

readonly

public static get abstract resourceName: String source

Resource name

Return:

String

Resource name

public static get resourcePath: String: string source

Resource path template

Return:

String

Path template

public static get resourceUrlKey: String: string source

Returns the url key of the resource

Return:

String

Resource key

Static Protected Members

protected static get protectedFields: Array<string>: string[] source

Protected read-only fields

Return:

Array<string>

Array containing protected read-only fields

Public Constructors

public constructor(api: Maps4News, data: Object<String, *>) source

Params:

NameTypeAttributeDescription
api Maps4News

Api instance

data Object<String, *>

Item data

Public Members

public get api: Maps4News: * source

Get api instance

Return:

Maps4News

Api instance

public set api(value: Maps4News) source

Set the api instance

public get baseUrl: string: string source

Auto generated Resource base url

Return:

string

Resource base url

public get fieldNames: Array<String>: * source

List fields that contain object data

Return:

Array<String>

A list of fields

public get ownable: boolean: boolean source

If the resource can be owned by an organisation

Return:

boolean

Can be owned by an organisation

public get url: string: * source

Auto generated resource url

Return:

string

Resource url

Public Methods

public clone(): ResourceBase source

Clone the object

Return:

ResourceBase

Exact clone of the object

public async refresh(updateSelf: Boolean): Promise<ResourceBase> source

Refresh the resource by requesting it from the server again

Params:

NameTypeAttributeDescription
updateSelf Boolean

Update the current instance

Return:

Promise<ResourceBase>

Refreshed instance

Throw:

ApiError

public reset(fields: Array<string> | string | null) source

Resets model instance to it's original state

Params:

NameTypeAttributeDescription
fields Array<string> | string | null
  • optional
  • default: null

Fields to reset, defaults to all fields

public sanitize() source

Clean up instance and commit all changes locally. This means that any changed fields will be marked as unchanged whilst keeping their new values. The changes will not be saved.

public static(Target: string | function, Constructor: function, seedData: Object<string, *>): SimpleResourceProxy source

Static proxy generation

Params:

NameTypeAttributeDescription
Target string | function

Constructor or url

Constructor function

Constructor for a resource that the results should be cast to

seedData Object<string, *>

Optional data to seed the resolved resources

Return:

SimpleResourceProxy

A proxy for accessing the resource

Example:

user.static('jobs').lister();
class FooBar extends ResourceBase {
   static get resourceName() {
     return 'custom';
   }
}

api.static(FooBar)
  .get(1)
  .then(console.log);

public toObject(camelCaseKeys: boolean): {} source

Transform instance to object

Params:

NameTypeAttributeDescription
camelCaseKeys boolean
  • optional
  • default: false

camelCase object keys

Return:

{}

object

public toString(): string source

String representation of the resource, similar to Python's repr

Return:

string

Resource name and id

Protected Methods

protected _proxyResourceList(Target: string | function, url: String, seedData: object): SimpleResourceProxy source

Macro for resource listing

Params:

NameTypeAttributeDescription
Target string | function

Target object

url String
  • nullable: true

Target url, if null it will guess

seedData object

Internal use, used for seeding SimpleResourceProxy::new

Return:

SimpleResourceProxy

A proxy for accessing the resource

protected _updateProperties() source

Moves new fields to this._properties and turns them into a getter/setter