backbone definitions (splitted PR)

This commit is contained in:
lgrignon
2015-12-15 15:48:20 +01:00
parent e3b69d13c8
commit f3917c6c0b
2 changed files with 57 additions and 0 deletions
@@ -0,0 +1,6 @@
/// <reference path="./backbone.localstorage.d.ts" />
var store: Store = new Store('testStore');
store.findAll();
store.save();
+51
View File
@@ -0,0 +1,51 @@
// Type definitions for backbone.localStorage 1.0.0
// Project: https://github.com/jeromegn/Backbone.localStorage
// Definitions by: Louis Grignon <https://github.com/lgrignon/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../backbone/backbone.d.ts" />
declare module Backbone {
interface Serializer {
serialize(item: any): any;
deserialize(data: any): any;
}
class LocalStorage {
name: string;
serializer: Serializer;
records: string[];
constructor(name: string, serializer?: Serializer);
save(): void;
// Add a model, giving it a (hopefully)-unique GUID, if it doesn't already
// have an id of it's own.
create(model: any): any;
// Update a model by replacing its copy in `this.data`.
update(model: any): any;
// Retrieve a model from `this.data` by id.
find(model: any): any;
// Return the array of all models currently in storage.
findAll(): any;
// Delete a model from `this.data`, returning it.
destroy<T>(model: T): T;
localStorage(): any;
// Clear localStorage for specific collection.
_clear(): void;
_storageSize(): number;
_itemName(id: any): string;
}
}
import Store = Backbone.LocalStorage;