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

Commit 3dbc8a0

Browse files
committed
new types like resources-by-id and by-type. now resource is separated from service
1 parent 5a0935e commit 3dbc8a0

17 files changed

Lines changed: 404 additions & 380 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-angular-jsonapi",
3-
"version": "0.4.15",
3+
"version": "0.5.0",
44
"description": "JSONAPI library developed for AngularJS in Typescript",
55
"repository": {
66
"type": "git",

src/demo/authors/authors.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as Jsonapi from '../../library/index';
44

5-
export class AuthorsService extends Jsonapi.Resource {
5+
export class AuthorsService extends Jsonapi.Service {
66
type = 'authors';
77
public schema: Jsonapi.ISchema = {
88
attributes: {

src/demo/books/books.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class BooksController {
3535

3636
// TEST 1
3737
// this test merge data with cache (this not include author or photos)
38+
console.log('book#1', (<IDataResource>this.books[1].relationships.author.data));
3839
console.log('book#1', (<IDataResource>this.books[1].relationships.author.data).attributes);
3940
// this.books = this.BooksService.all();
4041

src/demo/books/books.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as Jsonapi from '../../library/index';
44

5-
export class BooksService extends Jsonapi.Resource {
5+
export class BooksService extends Jsonapi.Service {
66
type = 'books';
77
public schema: Jsonapi.ISchema = {
88
attributes: {

src/demo/photos/photos.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as Jsonapi from '../../library/index';
44

5-
export class PhotosService extends Jsonapi.Resource {
5+
export class PhotosService extends Jsonapi.Service {
66
type = 'photos';
77
public schema: Jsonapi.ISchema = {
88
attributes: {

src/library/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ angular.module('rsJsonapi', [
2626
]);
2727

2828
import { Core } from './core';
29+
import { Service } from './service';
2930
import { Resource } from './resource';
3031

3132
// just for bootstrap this library on demo.
3233
// On dist version, all is exported inside a Jsonapi module
3334
export { Core };
3435
export { Resource };
36+
export { Service };
3537
export * from './interfaces';
3638
import { IResource } from './interfaces';
3739
import { IService } from './interfaces';

src/library/interfaces/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ export * from './relationships.d'
99
export * from './cache.d'
1010
export * from './params-collection.d'
1111
export * from './params-resource.d'
12+
export * from './resources-by-id.d'
13+
export * from './resources-by-type.d'
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
import { IRelationships, ICollection, ICache, IParamsResource } from './index';
1+
import { IRelationships, ICollection, IParamsResource, IService } from './index';
22

33
export interface IResource extends IDataResource {
44
is_new: boolean;
55
is_loading: boolean;
66
is_saving: boolean;
77
lastupdate?: number;
88

9-
memorycache: ICache;
10-
119
type: string; // dont work extend?
1210

1311
relationships: IRelationships; // redefined from IDataResource
1412

13+
// new? (): IResource;
1514
reset? (): void;
1615
addRelationship? (resource: IResource, type_alias?: string): void;
1716
addRelationships? (resources: ICollection, type_alias: string): void;
1817
removeRelationship? (type_alias: string, id: string): boolean;
1918
addRelationshipsArray <T extends IResource>(resources: Array<T>, type_alias?: string): void;
2019
save? (params?: IParamsResource, fc_success?: Function, fc_error?: Function): any;
2120
toObject? (params?: IParamsResource): IDataObject;
21+
22+
getService(): IService;
2223
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { IResource } from './resource';
2+
3+
export interface IResourcesById {
4+
[resource_id: string]: IResource;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { IResourcesById } from './resources-by-id';
2+
3+
export interface IResourcesByType {
4+
[type: string]: IResourcesById;
5+
}

0 commit comments

Comments
 (0)