@types/backbone
- Version 1.4.20
- Published
- 28.9 kB
- 2 dependencies
- MIT license
Install
npm i @types/backbone
yarn add @types/backbone
pnpm add @types/backbone
Overview
TypeScript definitions for backbone
Index
Variables
Functions
Classes
Collection
- [Symbol.iterator]()
- add()
- all()
- any()
- at()
- chain()
- clone()
- collect()
- comparator
- contains()
- countBy()
- create()
- detect()
- difference()
- drop()
- each()
- entries()
- every()
- extend()
- fetch()
- filter()
- find()
- findIndex()
- findLastIndex()
- findWhere()
- first()
- foldl()
- foldr()
- forEach()
- get()
- groupBy()
- has()
- head()
- include()
- includes()
- indexBy()
- indexOf()
- initial()
- initialize()
- inject()
- invoke()
- isEmpty()
- keys()
- last()
- lastIndexOf()
- length
- map()
- max()
- min()
- model
- modelId()
- models
- partition()
- pluck()
- pop()
- preinitialize()
- push()
- reduce()
- reduceRight()
- reject()
- remove()
- reset()
- rest()
- sample()
- select()
- set()
- shift()
- shuffle()
- size()
- slice()
- some()
- sort()
- sortBy()
- tail()
- take()
- toArray()
- unshift()
- url
- values()
- where()
- without()
Model
- attributes
- chain()
- changed
- changedAttributes()
- cid
- cidPrefix
- clear()
- clone()
- collection
- defaults()
- destroy()
- escape()
- extend()
- fetch()
- get()
- has()
- hasChanged()
- id
- idAttribute
- initialize()
- invert()
- isEmpty()
- isNew()
- isValid()
- keys()
- matches()
- omit()
- pairs()
- pick()
- preinitialize()
- previous()
- previousAttributes()
- save()
- set()
- unset()
- url
- urlRoot
- validate()
- validationError
- values()
Interfaces
Type Aliases
Variables
variable $
let $: JQueryStatic;
variable emulateHTTP
let emulateHTTP: boolean;
variable emulateJSON
let emulateJSON: boolean;
variable Events
const Events: Events;
variable history
const history: History;
Functions
function ajax
ajax: (options?: JQueryAjaxSettings) => JQueryXHR;
function noConflict
noConflict: () => typeof Backbone;
function sync
sync: ( method: string, model: | Model<any, ModelSetOptions, any> | Collection<Model<any, ModelSetOptions, any>>, options?: JQueryAjaxSettings) => any;
Classes
class Collection
class Collection<TModel extends Model = Model> extends ModelBase implements Events {}
constructor
constructor(models?: TModel[] | Record<string, any>[], options?: any);
property comparator
comparator: | string | ((element: TModel) => number | string) | ((compare: TModel, to?: TModel) => number);
Specify a model attribute name (string) or function that will be used to sort the collection.
property length
length: number;
property model
model: new (...args: any[]) => TModel;
property models
models: TModel[];
property url
url: _Result<string>;
Sets the url property (or function) on a collection to reference its location on the server.
method [Symbol.iterator]
[Symbol.iterator]: () => Iterator<TModel>;
method add
add: { (model: {} | TModel, options?: AddOptions): TModel; (models: ({} | TModel)[], options?: AddOptions): TModel[];};
method all
all: (iterator?: _.ListIterator<TModel, boolean>, context?: any) => boolean;
method any
any: (iterator?: _.ListIterator<TModel, boolean>, context?: any) => boolean;
method at
at: (index: number) => TModel;
method chain
chain: () => any;
method clone
clone: () => this;
method collect
collect: <TResult>( iterator: _.ListIterator<TModel, TResult>, context?: any) => TResult[];
method contains
contains: (value: TModel) => boolean;
method countBy
countBy: { (iterator?: _.ListIterator<TModel, any>): _.Dictionary<number>; (iterator: string): _.Dictionary<number>;};
method create
create: (attributes: any, options?: ModelSaveOptions) => TModel;
method detect
detect: (iterator: _.ListIterator<TModel, boolean>, context?: any) => TModel;
method difference
difference: (others: TModel[]) => TModel[];
method drop
drop: (n?: number) => TModel[];
method each
each: (iterator: _.ListIterator<TModel, void>, context?: any) => TModel[];
method entries
entries: () => Iterator<[any, TModel]>;
method every
every: (iterator: _.ListIterator<TModel, boolean>, context?: any) => boolean;
method extend
static extend: (properties: any, classProperties?: any) => any;
Do not use, prefer TypeScript's extend functionality.
method fetch
fetch: (options?: CollectionFetchOptions) => JQueryXHR;
method filter
filter: (iterator: _.ListIterator<TModel, boolean>, context?: any) => TModel[];
method find
find: (iterator: _.ListIterator<TModel, boolean>, context?: any) => TModel;
method findIndex
findIndex: (predicate: _.ListIterator<TModel, boolean>, context?: any) => number;
method findLastIndex
findLastIndex: ( predicate: _.ListIterator<TModel, boolean>, context?: any) => number;
method findWhere
findWhere: (properties: any) => TModel;
method first
first: { (): TModel; (n: number): TModel[] };
method foldl
foldl: <TResult>( iterator: _.MemoIterator<TModel, TResult>, memo?: TResult, context?: any) => TResult;
method foldr
foldr: <TResult>( iterator: _.MemoIterator<TModel, TResult>, memo?: TResult, context?: any) => TResult;
method forEach
forEach: (iterator: _.ListIterator<TModel, void>, context?: any) => TModel[];
method get
get: (id: string | number | Model<any, ModelSetOptions, any>) => TModel;
Get a model from a collection, specified by an id, a cid, or by passing in a model.
method groupBy
groupBy: ( iterator: _.ListIterator<TModel, any> | string, context?: any) => _.Dictionary<TModel[]>;
method has
has: (key: string | number | Model<any, ModelSetOptions, any>) => boolean;
method head
head: { (): TModel; (n: number): TModel[] };
method include
include: (value: TModel) => boolean;
method includes
includes: (value: TModel) => boolean;
method indexBy
indexBy: { (iterator: _.ListIterator<TModel, any>, context?: any): _.Dictionary<TModel>; (iterator: string, context?: any): _.Dictionary<TModel>;};
method indexOf
indexOf: (value: TModel, isSorted?: boolean) => number;
method initial
initial: { (): TModel; (n: number): TModel[] };
method initialize
initialize: ( models?: TModel[] | Array<Record<string, any>>, options?: any) => void;
method inject
inject: <TResult>( iterator: _.MemoIterator<TModel, TResult>, memo?: TResult, context?: any) => TResult;
method invoke
invoke: (methodName: string, ...args: any[]) => any;
method isEmpty
isEmpty: () => boolean;
method keys
keys: () => Iterator<any>;
method last
last: { (): TModel; (n: number): TModel[] };
method lastIndexOf
lastIndexOf: (value: TModel, from?: number) => number;
method map
map: <TResult>( iterator: _.ListIterator<TModel, TResult>, context?: any) => TResult[];
method max
max: (iterator?: _.ListIterator<TModel, any>, context?: any) => TModel;
method min
min: (iterator?: _.ListIterator<TModel, any>, context?: any) => TModel;
method modelId
modelId: (attrs: any) => any;
method partition
partition: (iterator: _.ListIterator<TModel, boolean>) => TModel[][];
method pluck
pluck: (attribute: string) => any[];
method pop
pop: (options?: Silenceable) => TModel;
method preinitialize
preinitialize: ( models?: TModel[] | Array<Record<string, any>>, options?: any) => void;
For use with collections as ES classes. If you define a preinitialize method, it will be invoked when the Collection is first created and before any instantiation logic is run for the Collection.
See Also
https://backbonejs.org/#Collection-preinitialize
method push
push: (model: TModel, options?: AddOptions) => TModel;
method reduce
reduce: <TResult>( iterator: _.MemoIterator<TModel, TResult>, memo?: TResult, context?: any) => TResult;
method reduceRight
reduceRight: <TResult>( iterator: _.MemoIterator<TModel, TResult>, memo?: TResult, context?: any) => TResult;
method reject
reject: (iterator: _.ListIterator<TModel, boolean>, context?: any) => TModel[];
method remove
remove: { (model: {} | TModel, options?: Silenceable): TModel; (models: ({} | TModel)[], options?: Silenceable): TModel[];};
method reset
reset: (models?: Array<{} | TModel>, options?: Silenceable) => TModel[];
method rest
rest: (n?: number) => TModel[];
method sample
sample: { (): TModel; (n: number): TModel[] };
method select
select: (iterator: _.ListIterator<TModel, boolean>, context?: any) => TModel[];
method set
set: (models?: Array<{} | TModel>, options?: CollectionSetOptions) => TModel[];
The set method performs a "smart" update of the collection with the passed list of models. If a model in the list isn't yet in the collection it will be added; if the model is already in the collection its attributes will be merged; and if the collection contains any models that aren't present in the list, they'll be removed. All of the appropriate "add", "remove", and "change" events are fired as this happens. Returns the touched models in the collection. If you'd like to customize the behavior, you can disable it with options: {add: false}, {remove: false}, or {merge: false}.
Parameter models
Parameter options
method shift
shift: (options?: Silenceable) => TModel;
method shuffle
shuffle: () => TModel[];
method size
size: () => number;
method slice
slice: (min?: number, max?: number) => TModel[];
Return a shallow copy of this collection's models, using the same options as native Array#slice.
method some
some: (iterator?: _.ListIterator<TModel, boolean>, context?: any) => boolean;
method sort
sort: (options?: Silenceable) => this;
method sortBy
sortBy: { (iterator?: _.ListIterator<TModel, any>, context?: any): TModel[]; (iterator: string, context?: any): TModel[];};
method tail
tail: (n?: number) => TModel[];
method take
take: { (): TModel; (n: number): TModel[] };
method toArray
toArray: () => TModel[];
method unshift
unshift: (model: TModel, options?: AddOptions) => TModel;
method values
values: () => Iterator<TModel>;
method where
where: (properties: any) => TModel[];
method without
without: (...values: TModel[]) => TModel[];
class EventsMixin
abstract class EventsMixin implements Events {}
Helper to avoid code repetition in type declarations. Backbone.Events cannot be extended, hence a separate abstract class with a different name. Both classes and interfaces can extend from this helper class to reuse the signatures.
For class type declarations that already extend another base class, and for actual class definitions, please see the Events_* interfaces above.
method bind
bind: { (eventName: string, callback: EventHandler, context?: any): this; (eventMap: EventMap, context?: any): this;};
method listenTo
listenTo: { (object: any, events: string, callback: EventHandler): this; (object: any, eventMap: EventMap): this;};
method listenToOnce
listenToOnce: { (object: any, events: string, callback: EventHandler): this; (object: any, eventMap: EventMap): this;};
method off
off: ( eventName?: string | null, callback?: EventHandler | null, context?: any) => this;
method on
on: { (eventName: string, callback: EventHandler, context?: any): this; (eventMap: EventMap, context?: any): this;};
method once
once: { (events: string, callback: EventHandler, context?: any): this; (eventMap: EventMap, context?: any): this;};
method stopListening
stopListening: (object?: any, events?: string, callback?: EventHandler) => this;
method trigger
trigger: (eventName: string, ...args: any[]) => this;
method unbind
unbind: (eventName?: string, callback?: EventHandler, context?: any) => this;
class History
class History extends EventsMixin implements Events {}
property handlers
handlers: any[];
property interval
interval: number;
property options
options: any;
property started
static started: boolean;
method atRoot
atRoot: () => boolean;
method checkUrl
checkUrl: (e?: any) => void;
method decodeFragment
decodeFragment: (fragment: string) => string;
method getFragment
getFragment: (fragment?: string) => string;
method getHash
getHash: (window?: Window) => string;
method getPath
getPath: () => string;
method getSearch
getSearch: () => string;
method loadUrl
loadUrl: (fragmentOverride?: string) => boolean;
method matchRoot
matchRoot: () => boolean;
method navigate
navigate: (fragment: string, options?: any) => boolean;
method route
route: (route: string | RegExp, callback: (fragment: string) => void) => number;
method start
start: (options?: HistoryOptions) => boolean;
method stop
stop: () => void;
class Model
class Model<T extends ObjectHash = any, S = ModelSetOptions, E = any> extends ModelBase implements Events {}
E - Extensions to the model constructor options. You can accept additional constructor options by listing them in the E parameter.
constructor
constructor( attributes?: ObjectHash, options?: ModelConstructorOptions<Model<any, ModelSetOptions, any>>);
property attributes
attributes: Partial<T>;
property changed
changed: Partial<T>;
property cid
cid: string;
property cidPrefix
cidPrefix: string;
property collection
collection: Collection<this>;
property id
id: string | number;
property idAttribute
idAttribute: string;
property url
url: () => string;
Returns the relative URL where the model's resource would be located on the server.
property urlRoot
urlRoot: _Result<string>;
property validationError
validationError: any;
method chain
chain: () => any;
method changedAttributes
changedAttributes: (attributes?: Partial<T>) => Partial<T> | false;
Return an object containing all the attributes that have changed, or false if there are no changed attributes. Useful for determining what parts of a view need to be updated and/or what attributes need to be persisted to the server. Unset attributes will be set to undefined. You can also pass an attributes object to diff against the model, determining if there *would be* a change.
method clear
clear: (options?: Silenceable) => this;
method clone
clone: () => Model<any, ModelSetOptions, any>;
method defaults
defaults: () => Partial<T>;
Default attributes for the model. It can be an object hash or a method returning an object hash. For assigning an object hash, do it like this: this.defaults = { attribute: value, ... }; That works only if you set it in the constructor or the initialize method.
method destroy
destroy: (options?: ModelDestroyOptions) => JQueryXHR | false;
method escape
escape: (attribute: _StringKey<T>) => string;
method extend
static extend: (properties: any, classProperties?: any) => any;
Do not use, prefer TypeScript's extend functionality.
method fetch
fetch: (options?: ModelFetchOptions) => JQueryXHR;
method get
get: <A extends _StringKey<T>>(attributeName: A) => T[A] | undefined;
For strongly-typed access to attributes, use the
get
method only privately in public getter properties.Example 1
get name(): string { return super.get("name"); }
method has
has: (attribute: _StringKey<T>) => boolean;
method hasChanged
hasChanged: (attribute?: _StringKey<T>) => boolean;
method initialize
initialize: ( attributes?: T, options?: CombinedModelConstructorOptions<E, this>) => void;
method invert
invert: () => any;
method isEmpty
isEmpty: () => boolean;
method isNew
isNew: () => boolean;
method isValid
isValid: (options?: any) => boolean;
method keys
keys: () => string[];
method matches
matches: (attrs: any) => boolean;
method omit
omit: { <A extends _StringKey<T>>(keys: A[]): Partial<_Omit<T, A>>; <A extends _StringKey<T>>(...keys: A[]): Partial<_Omit<T, A>>; (fn: (value: any, key: any, object: any) => any): Partial<T>;};
method pairs
pairs: () => any[];
method pick
pick: { <A extends _StringKey<T>>(keys: A[]): Partial<Pick<T, A>>; <A extends _StringKey<T>>(...keys: A[]): Partial<Pick<T, A>>; (fn: (value: any, key: any, object: any) => any): Partial<T>;};
method preinitialize
preinitialize: ( attributes?: T, options?: CombinedModelConstructorOptions<E, this>) => void;
For use with models as ES classes. If you define a preinitialize method, it will be invoked when the Model is first created, before any instantiation logic is run for the Model.
See Also
https://backbonejs.org/#Model-preinitialize
method previous
previous: <A extends _StringKey<T>>(attribute: A) => T[A] | null | undefined;
method previousAttributes
previousAttributes: () => Partial<T>;
method save
save: (attributes?: Partial<T> | null, options?: ModelSaveOptions) => JQueryXHR;
method set
set: { <A extends _StringKey<T>>(attributeName: A, value?: T[A], options?: S): this; (attributeName: Partial<T>, options?: S): this; <A extends _StringKey<T>>( attributeName: Partial<T> | A, value?: S | T[A], options?: S ): this;};
For strongly-typed assignment of attributes, use the
set
method only privately in public setter properties.Example 1
set name(value: string) { super.set("name", value); }
method unset
unset: (attribute: _StringKey<T>, options?: Silenceable) => this;
method validate
validate: (attributes: Partial<T>, options?: any) => any;
method values
values: () => any[];
class ModelBase
class ModelBase extends EventsMixin {}
class Router
class Router extends EventsMixin implements Events {}
constructor
constructor(options?: RouterOptions);
property routes
routes: _Result<RoutesHash>;
Routes hash or a method returning the routes hash that maps URLs with parameters to methods on your Router. For assigning routes as object hash, do it like this: this.routes = { "route": callback, ... }; That works only if you set it in the constructor or the initialize method.
method execute
execute: (callback: RouterCallback, args: string[], name: string) => void;
method extend
static extend: (properties: any, classProperties?: any) => any;
Do not use, prefer TypeScript's extend functionality.
method initialize
initialize: (options?: RouterOptions) => void;
method navigate
navigate: (fragment: string, options?: NavigateOptions | boolean) => this;
method preinitialize
preinitialize: (options?: RouterOptions) => void;
For use with Router as ES classes. If you define a preinitialize method, it will be invoked when the Router is first created, before any instantiation logic is run for the Router.
See Also
https://backbonejs.org/#Router-preinitialize
method route
route: { (route: string | RegExp, name: string, callback?: RouterCallback): this; (route: string | RegExp, callback: RouterCallback): this;};
class View
class View< TModel extends Model | undefined = Model, TElement extends Element = HTMLElement > extends EventsMixin implements Events {}
constructor
constructor(options?: ViewOptions<TModel, TElement>);
property $el
$el: JQuery;
property attributes
attributes: Record<string, any>;
property cid
cid: string;
property className
className?: string;
property collection
collection: Collection<any>;
property el
el: Element;
property events
events: _Result<EventsHash>;
Events hash or a method returning the events hash that maps events/selectors to methods on your View. For assigning events as object hash, do it like this: this.events = { "event:selector": callback, ... }; That works only if you set it in the constructor or the initialize method.
property id
id?: string;
property model
model: Model<any, ModelSetOptions, any>;
property tagName
tagName: string;
method $
$: (selector: string) => JQuery;
method delegate
delegate: ( eventName: string, selector: string, listener: ViewEventListener) => this;
method delegateEvents
delegateEvents: (events?: _Result<EventsHash>) => this;
method extend
static extend: (properties: any, classProperties?: any) => any;
Do not use, prefer TypeScript's extend functionality.
method initialize
initialize: (options?: ViewOptions<TModel, TElement>) => void;
method preinitialize
preinitialize: (options?: ViewOptions<TModel, TElement>) => void;
For use with views as ES classes. If you define a preinitialize method, it will be invoked when the view is first created, before any instantiation logic is run.
See Also
https://backbonejs.org/#View-preinitialize
method remove
remove: () => this;
method render
render: () => this;
method setElement
setElement: (element: TElement | JQuery) => this;
method undelegate
undelegate: ( eventName: string, selector?: string, listener?: ViewEventListener) => this;
method undelegateEvents
undelegateEvents: () => this;
Interfaces
interface AddOptions
interface AddOptions extends Silenceable {}
interface CollectionFetchOptions
interface CollectionFetchOptions extends PersistenceOptions, Parseable, CollectionSetOptions {}
property reset
reset?: boolean | undefined;
interface CollectionSetOptions
interface CollectionSetOptions extends Parseable, Silenceable {}
interface EventHandler
interface EventHandler {}
JavaScript events (used in the methods of the Events interface)
call signature
(...args: any[]): void;
interface EventMap
interface EventMap {}
index signature
[event: string]: EventHandler;
interface Events
interface Events extends EventsMixin {}
interface Events_Listen
interface Events_Listen<BaseT> {}
call signature
<T extends BaseT>( this: T, object: any, events: string, callback: EventHandler): T;
call signature
<T extends BaseT>(this: T, object: any, eventMap: EventMap): T;
interface Events_Off
interface Events_Off<BaseT> {}
call signature
<T extends BaseT>( this: T, eventName?: string | null, callback?: EventHandler | null, context?: any): T;
interface Events_On
interface Events_On<BaseT> {}
Helper shorthands for classes that implement the Events interface. Define your class like this:
import { Events, Events_On, Events_Off, Events_Trigger, Events_Listen, Events_Stop, } from 'backbone';
class YourClass implements Events { on: Events_On; off: Events_Off; trigger: Events_Trigger; bind: Events_On; unbind: Events_Off;
once: Events_On; listenTo: Events_Listen; listenToOnce: Events_Listen; stopListening: Events_Stop;
// ... (other methods) }
Object.assign(YourClass.prototype, Events); // can also use _.extend
If you are just writing a class type declaration that doesn't already extend some other base class, you can use the EventsMixin instead; see below.
call signature
<T extends BaseT>( this: T, eventName: string, callback: EventHandler, context?: any): T;
call signature
<T extends BaseT>(this: T, eventMap: EventMap, context?: any): T;
interface Events_Stop
interface Events_Stop<BaseT> {}
call signature
<T extends BaseT>( this: T, object?: any, events?: string, callback?: EventHandler): T;
interface Events_Trigger
interface Events_Trigger<BaseT> {}
call signature
<T extends BaseT>(this: T, eventName: string, ...args: any[]): T;
interface EventsHash
interface EventsHash {}
DOM events (used in the events property of a View)
index signature
[selector: string]: string | { (eventObject: JQuery.TriggeredEvent): void };
interface HistoryOptions
interface HistoryOptions extends Silenceable {}
property hashChange
hashChange?: boolean | undefined;
property pushState
pushState?: boolean | undefined;
property root
root?: string | undefined;
interface ModelConstructorOptions
interface ModelConstructorOptions<TModel extends Model = Model> extends ModelSetOptions, Parseable {}
property collection
collection?: Collection<TModel> | undefined;
interface ModelDestroyOptions
interface ModelDestroyOptions extends Waitable, PersistenceOptions {}
interface ModelFetchOptions
interface ModelFetchOptions extends PersistenceOptions, ModelSetOptions, Parseable {}
interface ModelSaveOptions
interface ModelSaveOptions extends Silenceable, Waitable, Validable, Parseable, PersistenceOptions {}
property patch
patch?: boolean | undefined;
interface ModelSetOptions
interface ModelSetOptions extends Silenceable, Validable {}
interface NavigateOptions
interface NavigateOptions {}
interface PersistenceOptions
interface PersistenceOptions extends Partial<_Omit<JQueryAjaxSettings, 'success' | 'error'>> {}
property emulateHTTP
emulateHTTP?: boolean | undefined;
property emulateJSON
emulateJSON?: boolean | undefined;
property error
error?: | ((modelOrCollection: any, response: any, options: any) => void) | undefined;
property success
success?: | ((modelOrCollection: any, response: any, options: any) => void) | undefined;
interface RouterOptions
interface RouterOptions {}
property routes
routes: _Result<RoutesHash>;
interface RoutesHash
interface RoutesHash {}
index signature
[routePattern: string]: string | { (...urlParts: string[]): void };
interface Silenceable
interface Silenceable {}
property silent
silent?: boolean | undefined;
interface ViewOptions
interface ViewOptions< TModel extends Model | undefined = Model, TElement extends Element = HTMLElement> {}
property attributes
attributes?: Record<string, any> | undefined;
property className
className?: string | undefined;
property collection
collection?: Collection<any> | undefined;
property el
el?: TElement | JQuery | string | undefined;
property events
events?: _Result<EventsHash> | undefined;
property id
id?: string | undefined;
property model
model?: TModel | undefined;
property tagName
tagName?: string | undefined;
Type Aliases
type CombinedModelConstructorOptions
type CombinedModelConstructorOptions< E, M extends Model<any, any, E> = Model> = ModelConstructorOptions<M> & E;
type ObjectHash
type ObjectHash = Record<string, any>;
type RouterCallback
type RouterCallback = (...args: string[]) => void;
type ViewEventListener
type ViewEventListener = (event: JQuery.Event) => void;
Package Files (1)
Dependencies (2)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/backbone
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/backbone)
- HTML<a href="https://www.jsdocs.io/package/@types/backbone"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 6207 ms. - Missing or incorrect documentation? Open an issue for this package.