Browse Source

Temp

pull/1/head
Sebastian 10 years ago
parent
commit
e83de94177
  1. 12
      src/Squidex/app/components/internal/app/settings/clients-page.component.ts
  2. 12
      src/Squidex/app/components/internal/app/settings/contributors-page.component.ts
  3. 10
      src/Squidex/app/components/internal/app/settings/languages-page.component.ts
  4. 1
      src/Squidex/app/framework/declarations.ts
  5. 12
      src/Squidex/app/framework/utils/immutable-list.ts
  6. 38
      src/Squidex/app/framework/utils/immutable-object.spec.ts
  7. 24
      src/Squidex/app/framework/utils/immutable-object.ts
  8. 6
      src/Squidex/app/framework/utils/immutable-set.ts

12
src/Squidex/app/components/internal/app/settings/clients-page.component.ts

@ -13,8 +13,8 @@ import {
AppClientsService,
AppComponentBase,
AppsStoreService,
ArrayHelper,
CreateAppClientDto,
ImmutableList,
NotificationService,
UpdateAppClientDto,
UsersProviderService
@ -30,7 +30,7 @@ function rename(client: AppClientDto, name: string) {
template
})
export class ClientsPageComponent extends AppComponentBase implements Ng2.OnInit {
public appClients: AppClientDto[];
public appClients: ImmutableList<AppClientDto>;
public createForm =
this.formBuilder.group({
@ -57,7 +57,7 @@ export class ClientsPageComponent extends AppComponentBase implements Ng2.OnInit
this.appName()
.switchMap(app => this.appClientsService.getClients(app).retry(2))
.subscribe(dtos => {
this.appClients = dtos;
this.appClients = new ImmutableList<AppClientDto>(dtos);
}, error => {
this.notifyError(error);
});
@ -67,7 +67,7 @@ export class ClientsPageComponent extends AppComponentBase implements Ng2.OnInit
this.appName()
.switchMap(app => this.appClientsService.deleteClient(app, client.id))
.subscribe(() => {
this.appClients = ArrayHelper.remove(this.appClients, client);
this.appClients = this.appClients.remove(client);
}, error => {
this.notifyError(error);
});
@ -77,7 +77,7 @@ export class ClientsPageComponent extends AppComponentBase implements Ng2.OnInit
this.appName()
.switchMap(app => this.appClientsService.updateClient(app, client.id, new UpdateAppClientDto(name)))
.subscribe(() => {
this.appClients = ArrayHelper.replace(this.appClients, client, rename(client, name));
this.appClients = this.appClients.update(client, c => rename(c, name));
}, error => {
this.notifyError(error);
});
@ -94,7 +94,7 @@ export class ClientsPageComponent extends AppComponentBase implements Ng2.OnInit
this.appName()
.switchMap(app => this.appClientsService.postClient(app, dto))
.subscribe(dto => {
this.appClients = ArrayHelper.push(this.appClients, dto);
this.appClients = this.appClients.add(dto);
this.reset();
}, error => {
this.notifyError(error);

12
src/Squidex/app/components/internal/app/settings/contributors-page.component.ts

@ -14,10 +14,10 @@ import {
AppContributorDto,
AppContributorsService,
AppsStoreService,
ArrayHelper,
AuthService,
AutocompleteItem,
AutocompleteSource,
ImmutableList,
NotificationService,
UserDto,
UsersProviderService,
@ -61,7 +61,7 @@ function changePermission(contributor: AppContributorDto, permission: string): A
template
})
export class ContributorsPageComponent extends AppComponentBase implements Ng2.OnInit {
public appContributors: AppContributorDto[] = [];
public appContributors = new ImmutableList<AppContributorDto>();
public currentUserId: string;
@ -95,7 +95,7 @@ export class ContributorsPageComponent extends AppComponentBase implements Ng2.O
this.appName()
.switchMap(app => this.appContributorsService.getContributors(app).retry(2))
.subscribe(dtos => {
this.appContributors = dtos;
this.appContributors = new ImmutableList<AppContributorDto>(dtos);
}, error => {
this.notifyError(error);
});
@ -114,7 +114,7 @@ export class ContributorsPageComponent extends AppComponentBase implements Ng2.O
this.appName()
.switchMap(app => this.appContributorsService.postContributor(app, contributor))
.subscribe(() => {
this.appContributors = ArrayHelper.push(this.appContributors, contributor);
this.appContributors = this.appContributors.add(contributor);
}, error => {
this.notifyError(error);
});
@ -126,7 +126,7 @@ export class ContributorsPageComponent extends AppComponentBase implements Ng2.O
this.appName()
.switchMap(app => this.appContributorsService.postContributor(app, newContributor))
.subscribe(() => {
this.appContributors = ArrayHelper.replace(this.appContributors, contributor, newContributor);
this.appContributors = this.appContributors.update(contributor, c => newContributor);
}, error => {
this.notifyError(error);
});
@ -136,7 +136,7 @@ export class ContributorsPageComponent extends AppComponentBase implements Ng2.O
this.appName()
.switchMap(app => this.appContributorsService.deleteContributor(app, contributor.contributorId))
.subscribe(() => {
this.appContributors = ArrayHelper.push(this.appContributors, contributor);
this.appContributors = this.appContributors.add(contributor);
}, error => {
this.notifyError(error);
});

10
src/Squidex/app/components/internal/app/settings/languages-page.component.ts

@ -13,9 +13,9 @@ import {
AppLanguageDto,
AppLanguagesService,
AppsStoreService,
ArrayHelper,
LanguageDto,
LanguageService,
ImmutableList,
NotificationService,
UpdateAppLanguageDto,
UsersProviderService
@ -28,7 +28,7 @@ import {
})
export class LanguagesPageComponent extends AppComponentBase implements Ng2.OnInit {
public allLanguages: LanguageDto[] = [];
public appLanguages: AppLanguageDto[] = [];
public appLanguages = new ImmutableList<AppLanguageDto>();
public selectedLanguage: LanguageDto | null = null;
@ -58,7 +58,7 @@ export class LanguagesPageComponent extends AppComponentBase implements Ng2.OnIn
this.appName()
.switchMap(app => this.appLanguagesService.getLanguages(app).retry(2))
.subscribe(dtos => {
this.appLanguages = dtos;
this.appLanguages = new ImmutableList<AppLanguageDto>();
}, error => {
this.notifyError(error);
});
@ -68,7 +68,7 @@ export class LanguagesPageComponent extends AppComponentBase implements Ng2.OnIn
this.appName()
.switchMap(app => this.appLanguagesService.postLanguages(app, new AddAppLanguageDto(this.selectedLanguage.iso2Code)))
.subscribe(dto => {
this.appLanguages = ArrayHelper.push(this.appLanguages, dto);
this.appLanguages = this.appLanguages.add(dto);
}, error => {
this.notifyError(error);
});
@ -80,7 +80,7 @@ export class LanguagesPageComponent extends AppComponentBase implements Ng2.OnIn
this.appName()
.switchMap(app => this.appLanguagesService.deleteLanguage(app, language.iso2Code))
.subscribe(dto => {
this.appLanguages = ArrayHelper.push(this.appLanguages, language);
this.appLanguages = this.appLanguages.remove(dto);
}, error => {
this.notifyError(error);
});

1
src/Squidex/app/framework/declarations.ts

@ -44,7 +44,6 @@ export * from './utils/date-time';
export * from './utils/duration';
export * from './utils/immutable-id-map';
export * from './utils/immutable-list';
export * from './utils/immutable-object';
export * from './utils/immutable-set';
export * from './utils/math-helper';
export * from './utils/modal-view';

12
src/Squidex/app/framework/utils/immutable-list.ts

@ -7,9 +7,13 @@
import * as Immutable from 'immutable';
export class ImmutableList<T> {
export class ImmutableList<T> implements Iterable<T> {
private readonly items: Immutable.List<T>;
public [Symbol.iterator](): Iterator<T> {
return this.items.values();
}
public get size(): number {
return this.items.size;
}
@ -17,7 +21,7 @@ export class ImmutableList<T> {
constructor(items?: T[] | Immutable.List<T>) {
if (Array.isArray(items)) {
this.items = Immutable.List<T>(items);
} else {
} else if (items) {
this.items = items || Immutable.List<T>();
}
@ -32,8 +36,8 @@ export class ImmutableList<T> {
return this.items.toArray();
}
public map<R>(projection: (item: T) => R): R[] {
return this.items.map(v => projection(v!)).toArray();
public map<R>(projection: (item: T) => R): ImmutableList<R> {
return new ImmutableList<R>(this.items.map(v => projection(v!)).toArray());
}
public filter(projection: (item: T) => boolean): T[] {

38
src/Squidex/app/framework/utils/immutable-object.spec.ts

@ -1,38 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { ImmutableObject } from './../';
class MockupObject extends ImmutableObject {
constructor(
public property1: string,
public property2: string
) {
super();
}
public changeProperty1(newValue: string): MockupObject {
return super.cloned<MockupObject>((x: MockupObject) => x.property1 = newValue);
}
public clone(): ImmutableObject {
return new MockupObject(this.property1, this.property2);
}
}
describe('ImmutableObject', () => {
it('should create new instance on update', () => {
const oldObj = new MockupObject('old1', 'old2');
const newObj = oldObj.changeProperty1('new1');
expect(oldObj.property1).toBe('old1');
expect(oldObj.property2).toBe('old2');
expect(newObj.property1).toBe('new1');
expect(newObj.property2).toBe('old2');
});
});

24
src/Squidex/app/framework/utils/immutable-object.ts

@ -1,24 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
/* tslint:disable:no-empty */
export abstract class ImmutableObject {
public abstract clone(): ImmutableObject;
protected afterClone() { }
protected cloned<T extends ImmutableObject>(updater: (instance: ImmutableObject) => void) {
const cloned = <T>this.clone();
updater(cloned);
cloned.afterClone();
return cloned;
}
}

6
src/Squidex/app/framework/utils/immutable-set.ts

@ -7,13 +7,17 @@
import * as Immutable from 'immutable';
export class ImmutableSet<T> {
export class ImmutableSet<T> implements Iterable<T> {
private readonly items: Immutable.Set<T>;
public get size(): number {
return this.items.size;
}
public [Symbol.iterator](): Iterator<T> {
return this.items.values();
}
constructor(items?: T[] | Immutable.Set<T>) {
if (Array.isArray(items)) {
this.items = Immutable.Set<T>(items);

Loading…
Cancel
Save