Skip to content
This repository was archived by the owner on Aug 18, 2018. It is now read-only.

Commit cb0d2a5

Browse files
committed
included resources are saved on store now
1 parent e6b3651 commit cb0d2a5

11 files changed

Lines changed: 211 additions & 89 deletions

File tree

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-angular-jsonapi",
3-
"version": "0.6.22",
3+
"version": "0.6.25",
44
"description": "JSONAPI library developed for AngularJS in Typescript",
55
"repository": {
66
"type": "git",
@@ -10,12 +10,12 @@
1010
"url": "https://github.com/reyesoft/ts-angular-jsonapi/issues"
1111
},
1212
"dependencies": {
13-
"angular": "<1.6.0",
13+
"angular": ">=1.4.0",
1414
"angular-localforage": "^1.3.0",
1515
"localforage-getitems": "^1.3.0"
1616
},
1717
"devDependencies": {
18-
"@types/angular": "^1.6.6",
18+
"@types/angular": "^1.6.4",
1919
"@types/angular-mocks": "^1.5.9",
2020
"@types/angular-ui-router": "^1.1.36",
2121
"@types/es6-shim": "^0.31.32",

src/library/core.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ export class Core implements ICore {
1212
public loadingsOffline = () => {};
1313

1414
public static me: ICore;
15-
public static injectedServices: any;
15+
public static injectedServices: {
16+
$q: ng.IQService,
17+
JsonapiStoreService: any,
18+
JsonapiHttp: any,
19+
rsJsonapiConfig: any
20+
};
1621

1722
/** @ngInject */
1823
public constructor(

src/library/interfaces/cache.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ICollection, IResource } from '../interfaces';
22

33
export interface ICache {
4-
setCollection(url: string, collection: ICollection): void;
54
setResource(resource: IResource): void;
65
deprecateCollections(path_start_with: string): boolean;
76
}

src/library/interfaces/cachememory.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface ICacheMemory extends ICache {
1010

1111
isResourceLive(id: string, ttl: number): boolean;
1212
getOrCreateResource(type: string, id: string): IResource;
13+
setCollection(url: string, collection: ICollection): void;
1314

1415
removeResource(id: string): void;
1516
}

src/library/interfaces/cachestore.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import { ICache } from '../interfaces/cache.d';
33

44
export interface ICacheStore extends ICache {
55
getResource(resource: IResource): ng.IPromise<object>;
6-
getCollectionFromStorePromise(url:string, collection: ICollection): ng.IPromise<ICollection>;
6+
getCollectionFromStorePromise(url:string, includes: Array<string>, collection: ICollection): ng.IPromise<ICollection>;
7+
setCollection(url: string, collection: ICollection, include: Array<string>): void;
78
}

src/library/interfaces/core.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,12 @@ export interface ICore {
1717

1818
// static
1919
me?: IService;
20-
injectedServices?: any;
20+
21+
// defined on core code too
22+
injectedServices?: {
23+
$q: ng.IQService,
24+
JsonapiStoreService: any,
25+
JsonapiHttp: any,
26+
rsJsonapiConfig: any
27+
};
2128
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { IDataResource } from './data-resource';
22
import { IDocument } from '../interfaces/document';
3+
import { IPage } from './page';
34

45
interface IDataCollection extends IDocument {
56
data: IDataResource[];
7+
page?: IPage;
8+
_lastupdate_time?: number; // used when come from Store
69
}

src/library/service.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,20 @@ export class Service extends ParentResourceService implements IService {
102102
});
103103
resource.is_loading = false;
104104
return resource;
105-
}
106-
107-
// CACHESTORE
108-
this.getService().cachestore.getResource(resource)
109-
.then(
110-
success => {
105+
} else {
106+
// CACHESTORE
107+
this.getService().cachestore.getResource(resource)
108+
.then(success => {
111109
if (Base.isObjectLive(temporal_ttl, resource.lastupdate)) {
112110
this.runFc(fc_success, { data: success});
113111
} else {
114112
this.getGetFromServer(path, fc_success, fc_error, resource);
115113
}
116-
},
117-
error => {
114+
})
115+
.catch(error => {
118116
this.getGetFromServer(path, fc_success, fc_error, resource);
119-
}
120-
);
117+
});
118+
}
121119

122120
return resource;
123121
}
@@ -205,7 +203,8 @@ export class Service extends ParentResourceService implements IService {
205203
} else {
206204
// STORE
207205
tempororay_collection.$is_loading = true;
208-
this.getService().cachestore.getCollectionFromStorePromise(path.getForCache(), tempororay_collection)
206+
207+
this.getService().cachestore.getCollectionFromStorePromise(path.getForCache(), path.includes, tempororay_collection)
209208
.then(
210209
success => {
211210
tempororay_collection.$source = 'store';
@@ -253,7 +252,7 @@ export class Service extends ParentResourceService implements IService {
253252
Converter.build(success.data, tempororay_collection);
254253

255254
this.getService().cachememory.setCollection(path.getForCache(), tempororay_collection);
256-
this.getService().cachestore.setCollection(path.getForCache(), tempororay_collection);
255+
this.getService().cachestore.setCollection(path.getForCache(), tempororay_collection, params.include);
257256

258257
// localfilter getted data
259258
let localfilter = new LocalFilter(params.localfilter);
@@ -307,8 +306,10 @@ export class Service extends ParentResourceService implements IService {
307306
}
308307

309308
public clearCacheMemory(): boolean {
310-
return this.getService().cachememory.deprecateCollections(this.type) &&
311-
this.getService().cachestore.deprecateCollections(this.type);
309+
let path = new PathBuilder();
310+
path.applyParams(this);
311+
return this.getService().cachememory.deprecateCollections(path.getForCache()) &&
312+
this.getService().cachestore.deprecateCollections(path.getForCache());
312313
}
313314

314315
public parseFromServer(attributes: IAttributes): void {

0 commit comments

Comments
 (0)