Skip to content

Commit

Permalink
Remove ImmutableJS
Browse files Browse the repository at this point in the history
  • Loading branch information
widoz committed Jan 20, 2024
1 parent d41077e commit ae2f058
Show file tree
Hide file tree
Showing 34 changed files with 376 additions and 310 deletions.
100 changes: 50 additions & 50 deletions @types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { OrderedSet, Set } from 'immutable';
import React from 'react';
import type { Set } from '../sources/client/src/vo/set';

import { BaseEntityRecords, Context } from '@wordpress/core-data';

Expand All @@ -19,7 +19,7 @@ declare namespace EntitiesSearch {
fields: EntitiesSearch.SearchQueryFields;
[p: string]: unknown;
}>
> {}
> { }

interface SearchEntityFields
extends Readonly<{
Expand All @@ -28,7 +28,7 @@ declare namespace EntitiesSearch {
url: string;
type: string;
subtype: string;
}> {}
}> { }

type ControlOption<V extends any> = Readonly<{
value: V;
Expand All @@ -37,39 +37,39 @@ declare namespace EntitiesSearch {

type SingularControl<V> = {
[K in keyof BaseControl<V>]: K extends 'value'
? V
: K extends 'onChange'
? (value: V) => void
: BaseControl<V>[K];
? V
: K extends 'onChange'
? (value: V) => void
: BaseControl<V>[K];
};

interface BaseControl<V>
extends Readonly<{
value: OrderedSet<V>;
options: OrderedSet<ControlOption<V>>;
value: Set<V>;
options: Set<ControlOption<V>>;
onChange(values: BaseControl<V>['value']): void;
}> {}
}> { }

/*
* Hooks
*/
type ViewablePostType = Readonly<{
[K in keyof PostType<'edit'>]: K extends 'viewable'
? true
: PostType<'edit'>[K];
? true
: PostType<'edit'>[K];
}>;

// TODO Need Type Test.
type ViewableTaxonomy = Readonly<{
[K in keyof Taxonomy<'edit'>]: K extends 'visibility'
? BaseEntityRecords.TaxonomyVisibility & {
publicly_queryable: true;
}
: Taxonomy<'edit'>[K];
? BaseEntityRecords.TaxonomyVisibility & {
publicly_queryable: true;
}
: Taxonomy<'edit'>[K];
}>;

type EntitiesRecords<Entity> = Readonly<{
records(): OrderedSet<Entity>;
records(): Set<Entity>;
isResolving(): boolean;
errored(): boolean;
succeed(): boolean;
Expand All @@ -88,45 +88,45 @@ declare namespace EntitiesSearch {
interface EntitiesState<
E,
K,
OptionSet = OrderedSet<EntitiesSearch.ControlOption<E>>
OptionSet = Set<EntitiesSearch.ControlOption<E>>
> extends Readonly<{
entities: BaseControl<E>['value'];
kind: BaseControl<K>['value'];
contextualEntitiesOptions: OptionSet;
currentEntitiesOptions: OptionSet;
selectedEntitiesOptions: OptionSet;
}> {}
entities: BaseControl<E>['value'];
kind: BaseControl<K>['value'];
contextualEntitiesOptions: OptionSet;
currentEntitiesOptions: OptionSet;
selectedEntitiesOptions: OptionSet;
}> { }

type StoreAction<E, K> =
| {
type: 'UPDATE_ENTITIES';
entities: EntitiesState<E, K>['entities'];
}
type: 'UPDATE_ENTITIES';
entities: EntitiesState<E, K>['entities'];
}
| {
type: 'UPDATE_KIND';
kind: EntitiesState<E, K>['kind'];
}
type: 'UPDATE_KIND';
kind: EntitiesState<E, K>['kind'];
}
| {
type: 'UPDATE_CURRENT_ENTITIES_OPTIONS';
currentEntitiesOptions: EntitiesState<
E,
K
>['currentEntitiesOptions'];
}
type: 'UPDATE_CURRENT_ENTITIES_OPTIONS';
currentEntitiesOptions: EntitiesState<
E,
K
>['currentEntitiesOptions'];
}
| {
type: 'UPDATE_CONTEXTUAL_ENTITIES_OPTIONS';
contextualEntitiesOptions: EntitiesState<
E,
K
>['contextualEntitiesOptions'];
}
type: 'UPDATE_CONTEXTUAL_ENTITIES_OPTIONS';
contextualEntitiesOptions: EntitiesState<
E,
K
>['contextualEntitiesOptions'];
}
| {
type: 'UPDATE_SELECTED_ENTITIES_OPTIONS';
selectedEntitiesOptions: EntitiesState<
E,
K
>['selectedEntitiesOptions'];
};
type: 'UPDATE_SELECTED_ENTITIES_OPTIONS';
selectedEntitiesOptions: EntitiesState<
E,
K
>['selectedEntitiesOptions'];
};

/*
* Components
Expand All @@ -135,7 +135,7 @@ declare namespace EntitiesSearch {
extends Readonly<{
id?: string;
onChange(phrase: string | React.ChangeEvent<HTMLInputElement>);
}> {}
}> { }

interface CompositeEntitiesKinds<E, K>
extends Readonly<{
Expand All @@ -155,5 +155,5 @@ declare namespace EntitiesSearch {
phrase: Parameters<SearchControl<E, K>['search']>[0]
) => ReturnType<SearchControl<E, K>['search']>
): React.ReactNode;
}> {}
}> { }
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"@wordpress/core-data": "~6.12.0",
"@wordpress/i18n": "~4.24.0",
"classnames": "^2.3.2",
"immutable": "~4.3.0",
"react": "~18.2.0"
},
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions sources/client/src/api/search-entities.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import EntitiesSearch from '@types';
import { OrderedSet } from 'immutable';

import { Set } from '../vo/set';
import { fetch } from './fetch';

export async function searchEntities<E>(
type: string,
subtype: OrderedSet<string>,
subtype: Set<string>,
phrase: string,
queryArguments?: EntitiesSearch.QueryArguments<string>
): Promise<OrderedSet<E>> {
): Promise<Set<E>> {
const {
exclude,
include,
Expand All @@ -26,7 +26,7 @@ export async function searchEntities<E>(
include: include?.toArray() ?? [],
...restArguments,
},
type: type,
type,
search: phrase,
subtype: subtype.toArray(),
_fields: serializeFields(fields),
Expand All @@ -37,7 +37,7 @@ export async function searchEntities<E>(
path: `?rest_route=/wp/v2/search&${params.toString()}`,
});

return OrderedSet(entities);
return new Set(entities);
}

function serializeFields(fields: EntitiesSearch.SearchQueryFields): string {
Expand Down
Loading

0 comments on commit ae2f058

Please sign in to comment.