Skip to content

Commit

Permalink
console.log only on dev mode (#109)
Browse files Browse the repository at this point in the history
* removeRelationship hasMany fixed. console.log only on development mode
  • Loading branch information
pablorsk committed Sep 9, 2018
1 parent aaac8ef commit cd063ec
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, Optional } from '@angular/core';
import { Injectable, Optional, isDevMode } from '@angular/core';
import { Service } from './service';
import { Resource } from './resource';
import { JsonapiConfig } from './jsonapi-config';
Expand Down Expand Up @@ -61,10 +61,10 @@ export class Core {

if (error.status <= 0) {
// offline?
if (!Core.me.loadingsOffline(error)) {
if (!Core.me.loadingsOffline(error) && isDevMode()) {
console.warn('Jsonapi.Http.exec (use JsonapiCore.loadingsOffline for catch it) error =>', error);
}
} else if (call_loadings_error && !Core.me.loadingsError(error)) {
} else if (call_loadings_error && !Core.me.loadingsError(error) && isDevMode()) {
console.warn('Jsonapi.Http.exec (use JsonapiCore.loadingsError for catch it) error =>', error);
}

Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-jsonapi",
"version": "2.0.0-rc.1",
"version": "2.0.0-rc.2",
"description": "JSON API library for Angular",
"module": "ngx-jsonapi/@ngx-jsonapi/ngx-jsonapi.es5.js",
"es2015": "ngx-jsonapi/@ngx-jsonapi/ngx-jsonapi.js",
Expand Down
13 changes: 9 additions & 4 deletions src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,16 @@ export class Resource implements ICacheable {
return false;
}

if (this.relationships[type_alias] instanceof DocumentCollection) {
console.warn('@todo removeRelationship');
// delete this.relationships[type_alias].data[id]; @todo
let relation = this.relationships[type_alias];
if (relation instanceof DocumentCollection) {
for (let i = 0; i < relation.data.length; i++) {
if (relation.data[i].id === id) {
delete relation.data[i];
break;
}
}
} else {
this.relationships[type_alias].data = [];
relation.data.reset();
}

return true;
Expand Down
3 changes: 2 additions & 1 deletion src/services/cachestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DocumentCollection } from '../document-collection';
import { Observable, Subject } from 'rxjs';
import { Page } from './page';
import { DocumentResource } from '../document-resource';
import { isDevMode } from '@angular/core';

export class CacheStore {
public async getResource(resource: Resource, include: Array<string> = []): Promise<object> {
Expand Down Expand Up @@ -243,7 +244,7 @@ export class CacheStore {
if (builded_resource.is_new) {
// no est谩 en memoria, la pedimos a store
include_promises.push(this.getResource(builded_resource));
} else {
} else if (isDevMode()) {
console.warn('ts-angular-json: esto no deber铆a pasar #isdjf2l1a');
}
resource.addRelationship(builded_resource, resource_alias);
Expand Down
16 changes: 8 additions & 8 deletions src/services/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { Core } from '../core';
import { Resource } from '../resource';
import { Service } from '../service';
import { IResourcesByType, IObjectsById } from '../interfaces';
import { ResourceRelationshipsConverter } from './resource-relationships-converter';
import { IDataObject } from '../interfaces/data-object';
import { IDataCollection } from '../interfaces/data-collection';
import { IDataResource } from '../interfaces/data-resource';
import { Base } from '../services/base';
import { DocumentCollection } from '../document-collection';
import { isDevMode } from '@angular/core';

export class Converter<R extends Resource> {
/*
Expand Down Expand Up @@ -36,11 +34,13 @@ export class Converter<R extends Resource> {
if (resource_service) {
return Converter.procreate(json_resource);
} else {
console.warn(
'`' + json_resource.type + '`',
'service not found on json2resource().',
'Use @Autoregister() on service and inject it on component.'
);
if (isDevMode()) {
console.warn(
'`' + json_resource.type + '`',
'service not found on json2resource().',
'Use @Autoregister() on service and inject it on component.'
);
}
let temp = new Resource();
temp.id = json_resource.id;
temp.type = json_resource.type;
Expand Down
13 changes: 8 additions & 5 deletions src/services/resource-relationships-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Resource } from '../resource';
import { DocumentCollection } from '../document-collection';
import { IRelationships } from '../interfaces/relationship';
import { DocumentResource } from '../document-resource';
import { isDevMode } from '@angular/core';

export class ResourceRelationshipsConverter {
private getService: Function;
Expand Down Expand Up @@ -52,11 +53,13 @@ export class ResourceRelationshipsConverter {

relation_alias = relation_alias || relation_type;
if (!this.getService(relation_type)) {
console.warn(
'The relationship ' + relation_alias + ' (type',
relation_type,
') cant be generated because service for this type has not been injected.'
);
if (isDevMode()) {
console.warn(
'The relationship ' + relation_alias + ' (type',
relation_type,
') cant be generated because service for this type has not been injected.'
);
}

return;
}
Expand Down

0 comments on commit cd063ec

Please sign in to comment.