Skip to content

Commit

Permalink
Renamed BareField
Browse files Browse the repository at this point in the history
  • Loading branch information
smikhalevski committed Feb 6, 2024
1 parent 8d2b8e3 commit 88177b2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 28 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ planetsField.parent;
// ⮕ universeField
```

Fields returned by the [`Field.at`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.FieldBase.html#at)
Fields returned by the [`Field.at`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.BareField.html#at)
method have a stable identity. This means that you can invoke `at` with the same key multiple times and the same field
instance is returned:

Expand Down Expand Up @@ -186,14 +186,14 @@ const unsubscribe = planetsField.on('change:value', event => {
// ⮕ () => void
```

The [`Field.on`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.FieldBase.html#on) method
The [`Field.on`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.BareField.html#on) method
associates the event subscriber with an event type. All events that are dispatched onto fields have the share
[`Event`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.Event.html).

Without plugins, fields can dispatch events with
[`change:value`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.FieldBase.html#on.on-2) type. This
[`change:value`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.BareField.html#on.on-2) type. This
event is dispatched when the field value is changed via
[`Field.setValue`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.FieldBase.html#setValue).
[`Field.setValue`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.BareField.html#setValue).

Plugins may dispatch their own events. Here's an example of the
[`change:errors`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.ErrorsPlugin.html#on.on-1) event
Expand Down Expand Up @@ -234,7 +234,7 @@ planetsField.on('*', event => {

# Transient updates

When you call [`Field.setValue`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.FieldBase.html#setValue)
When you call [`Field.setValue`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.BareField.html#setValue)
on a field then subscribers of its ancestors and its updated child fields are triggered. To manually control the update
propagation to fields ancestors, you can use transient updates.

Expand All @@ -261,7 +261,7 @@ avatarField.at('eyeColor').isTransient;
```

To propagate the transient value contained by the child field to its parent, use the
[`Field.propagate`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.FieldBase.html#propagate)
[`Field.propagate`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.BareField.html#propagate)
method:

```ts
Expand All @@ -271,7 +271,7 @@ avatarField.value;
// ⮕ { eyeColor: 'green' }
```

[`Field.setTransientValue`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.FieldBase.html#setTransientValue)
[`Field.setTransientValue`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.BareField.html#setTransientValue)
can be called multiple times, but only the most recent update is propagated to the parent field after the `propagate`
call.

Expand Down Expand Up @@ -308,12 +308,12 @@ planetsField.at(1).value;
updates field values.

- When the child field is accessed via
[`Field.at`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.FieldBase.html#at) method for the
[`Field.at`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.BareField.html#at) method for the
first time, its value is read from the value of the parent field using the
[`ValueAccessor.get`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.Accessor.html#get) method.

- When a field value is updated via
[`Field.setValue`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.FieldBase.html#setValue), then
[`Field.setValue`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.BareField.html#setValue), then
the parent field value is updated with the value returned from the
[`ValueAccessor.set`](https://smikhalevski.github.io/roqueform/interfaces/roqueform.Accessor.html#set) method. If the
updated field has child fields, their values are updated with values returned from the
Expand Down
2 changes: 1 addition & 1 deletion packages/doubter-plugin/src/main/doubterPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

export interface DoubterShapePlugin {
/**
* The shape that Doubter uses to validate {@link FieldBase.value the field value}, or `null` if there's no
* The shape that Doubter uses to validate {@link BareField.value the field value}, or `null` if there's no
* shape for this field.
*/
valueShape: Shape | null;
Expand Down
8 changes: 4 additions & 4 deletions packages/reset-plugin/src/main/resetPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isDeepEqual from 'fast-deep-equal';
import {
dispatchEvents,
Event,
Expand All @@ -9,7 +10,6 @@ import {
Unsubscribe,
ValueOf,
} from 'roqueform';
import isDeepEqual from 'fast-deep-equal';

/**
* The plugin added to fields by the {@link resetPlugin}.
Expand All @@ -33,15 +33,15 @@ export interface ResetPlugin {
reset(): void;

/**
* Returns all fields that have {@link roqueform!FieldBase.value a value} that is different from
* {@link roqueform!FieldBase.initialValue an initial value}.
* Returns all fields that have {@link roqueform!BareField.value a value} that is different from
* {@link roqueform!BareField.initialValue an initial value}.
*
* @see {@link isDirty}
*/
getDirtyFields(): Field<any, PluginOf<this>>[];

/**
* Subscribes to changes of {@link roqueform!FieldBase.initialValue the initial value}.
* Subscribes to changes of {@link roqueform!BareField.initialValue the initial value}.
*
* @param eventType The type of the event.
* @param subscriber The subscriber that would be triggered.
Expand Down
10 changes: 5 additions & 5 deletions packages/roqueform/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export { validationPlugin } from './validationPlugin';
export type { ClearErrorsOptions, ErrorsPlugin } from './errorsPlugin';
export type { Validator, Validation, ValidationPlugin } from './validationPlugin';
export type {
Field,
BareField,
Event,
Field,
PluginInjector,
PluginOf,
Subscriber,
Unsubscribe,
PluginOf,
ValueOf,
FieldBase,
PluginInjector,
ValueAccessor,
ValueOf,
} from './types';
9 changes: 4 additions & 5 deletions packages/roqueform/src/main/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
* @template Value The field value.
* @template Plugin The plugin injected into the field.
*/
export type Field<Value = any, Plugin = any> = FieldBase<Value, PreferAny<Plugin>> & PreferUnknown<Plugin>;
export type Field<Value = any, Plugin = any> = BareField<Value, PreferAny<Plugin>> & PreferUnknown<Plugin>;

/**
* The field controller provides the core field functionality.
* The bare field provides the core field functionality.
*
* @template Value The field value.
* @template Plugin The plugin injected into the field.
*/
export interface FieldBase<Value = any, Plugin = any> {
export interface BareField<Value = any, Plugin = any> {
/**
* Holds the plugin type for inference.
*
Expand Down Expand Up @@ -175,8 +175,7 @@ export type Unsubscribe = () => void;
/**
* Infers plugins that were injected into a field
*
* Use `PluginOf<this>` in plugin interfaces to infer all plugin interfaces that were intersected with the field
* controller.
* Use `PluginOf<this>` in plugin interfaces to infer all plugin interfaces that were intersected with the bare field.
*
* @template T The field to infer plugin of.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/roqueform/src/main/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Event, FieldBase } from './types';
import type { BareField, Event } from './types';

/**
* [SameValueZero](https://262.ecma-international.org/7.0/#sec-samevaluezero) comparison operation.
Expand Down Expand Up @@ -46,7 +46,7 @@ export function dispatchEvents(events: readonly Event[]): void {
continue;
}

for (let ancestor: FieldBase | null = event.targetField; ancestor !== null; ancestor = ancestor.parentField) {
for (let ancestor: BareField | null = event.targetField; ancestor !== null; ancestor = ancestor.parentField) {
const subscribers1 = ancestor.subscribers[event.type];
const subscribers2 = ancestor.subscribers['*'];

Expand Down
4 changes: 2 additions & 2 deletions packages/zod-plugin/src/main/zodPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
BareField,
composePlugins,
errorsPlugin,
ErrorsPlugin,
Field,
FieldBase,
PluginInjector,
Validation,
validationPlugin,
Expand Down Expand Up @@ -99,7 +99,7 @@ function getValue(field: Field<ZodPlugin>): unknown {
return value;
}

function getPath(field: FieldBase): any[] {
function getPath(field: BareField): any[] {
const path = [];

while (field.parentField !== null) {
Expand Down

0 comments on commit 88177b2

Please sign in to comment.