add method: 'replace' definition

This commit is contained in:
deepfunc
2018-06-20 18:04:51 +08:00
parent 7eae3c4d77
commit 45cedb7649
2 changed files with 18 additions and 0 deletions
+8
View File
@@ -18,6 +18,10 @@ declare namespace SeamlessImmutable {
merger?(a: any, b: any, config: any): any;
}
interface ReplaceConfig {
deep: boolean;
}
interface Options {
prototype?: any;
}
@@ -75,6 +79,8 @@ declare namespace SeamlessImmutable {
without<K extends keyof T>(property: K): ImmutableObject<T>;
without<K extends keyof T>(...properties: K[]): ImmutableObject<T>;
without<K extends keyof T>(filter: (value: T[K], key: K) => boolean): ImmutableObject<T>;
replace<S>(valueObj: S, options?: ReplaceConfig): ImmutableObject<S>;
}
interface ImmutableArrayMixin<T> {
@@ -92,6 +98,8 @@ declare namespace SeamlessImmutable {
function isImmutable(target: any): boolean;
function ImmutableError(message: string): Error;
function replace<T, S>(obj: ImmutableObject<T>, valueObj: S, options?: ReplaceConfig): ImmutableObject<S>;
}
declare function SeamlessImmutable<T>(obj: T[], options?: SeamlessImmutable.Options): SeamlessImmutable.ImmutableArray<T>;
@@ -44,6 +44,12 @@ interface ExtendedUser extends User {
{
const isImmutable: boolean = Immutable.isImmutable(Immutable.from([0, 2]));
const user1: Immutable.ImmutableObject<User> = Immutable.from({
firstName: 'Angry',
lastName: 'Monkey'
});
const replacedUser01 = Immutable.replace(user1, { firstName: 'Super', lastName: 'Monkey' });
const replacedUser02 = Immutable.replace(user1, { firstName: 'Super', lastName: 'Monkey' }, { deep: true });
}
//
@@ -124,4 +130,8 @@ interface ExtendedUser extends User {
const firstNameWithDynamicPathWithDefault = immutableUser.getIn(['first' + 'name'], '');
const line1WithoutDefault = immutableUserEx.getIn(['address', 'line1']);
const line1WithDefault = immutableUserEx.getIn(['address', 'line1'], '');
// replace
const replacedUser01 = immutableUser.replace({ firstName: 'Super', lastName: 'Monkey' });
const replacedUser02 = immutableUser.replace({ firstName: 'Super', lastName: 'Monkey' }, { deep: true });
}