Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 69af029

Browse files
committed
fixed typos
1 parent b273328 commit 69af029

File tree

18 files changed

+348
-288
lines changed

18 files changed

+348
-288
lines changed

examples/react/develop/multieditor-ts/src/core/signUpEditor.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import {
1515
import { globalBind } from '@agile-ts/core';
1616
import * as Yup from 'yup';
1717
import { generateColor, generateId, isLight } from './utils';
18+
import { assignSharedLogger, createLogger, Logger } from '@agile-ts/logger';
19+
20+
assignSharedLogger(createLogger({ level: Logger.level.DEBUG }));
1821

1922
export const isValidNameValidator = agileResolver(
2023
isRequired,
@@ -32,8 +35,8 @@ export const signUpEditor = createMultieditor((editor) => ({
3235
gender: undefined,
3336
userName: '',
3437
email: '',
35-
aboutYou: '',
3638
age: undefined,
39+
aboutYou: '',
3740
image: {
3841
id: generateId(),
3942
color: generateColor(),
@@ -49,24 +52,27 @@ export const signUpEditor = createMultieditor((editor) => ({
4952
// Validation with Yup
5053
lastName: yupResolver(
5154
Yup.string()
55+
.required()
5256
.min(2)
5357
.max(10)
5458
.matches(/^([^0-9]*)$/, 'No Numbers allowed!')
5559
),
5660

5761
// Outsourced Validator with additional validation method
58-
userName: isValidNameValidator.addValidationMethod(
59-
async (key, value, editor) => {
62+
userName: isValidNameValidator
63+
.copy()
64+
.addValidationMethod(async (key, value, editor) => {
6065
const isValid = value === 'Jeff';
6166
if (!isValid)
6267
editor.setStatus(key, 'error', 'Sry only the name Jeff is allowed!');
6368
return isValid;
64-
}
65-
),
69+
}),
6670

6771
// Validation with Agile
6872
email: agileResolver(isRequired, isString, isEmail),
6973

74+
age: agileResolver(isRequired, isNumber, minNumber(18), maxNumber(100)),
75+
7076
// Validation with Yup and Agile
7177
aboutYou: agileResolver(isRequired)
7278
.append(yupResolver(Yup.string().min(10)))
@@ -76,7 +82,6 @@ export const signUpEditor = createMultieditor((editor) => ({
7682
editor.setStatus(key, 'error', 'The word fuck is not allowed!');
7783
return isValid;
7884
}),
79-
age: agileResolver(isRequired, isNumber, minNumber(18), maxNumber(100)),
8085

8186
gender: agileResolver(isRequired),
8287

packages/core/src/computed/computed.tracker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class ComputedTracker {
1414
}
1515

1616
/**
17-
* Activates Computed Tracker to globally track used Observers.
17+
* Activates the Computed Tracker to globally track used Observers.
1818
*
1919
* @internal
2020
*/
@@ -24,7 +24,7 @@ export class ComputedTracker {
2424

2525
/**
2626
* Tracks the specified Observer and caches it
27-
* when the Computed Tracker is actively tracking.
27+
* if the Computed Tracker is actively tracking.
2828
*
2929
* @internal
3030
* @param observer - Observer

packages/multieditor/README.md

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,75 @@
1414
<img src="https://img.shields.io/bundlephobia/min/@agile-ts/multieditor.svg" alt="npm minified size"/></a>
1515

1616

17-
## ⏰ Short Example
17+
## 👀 Example
1818
```ts
19-
// Let's create our MultiEditor
20-
const multiEditor = new MultiEditor(editor => ({
19+
// Create Multieditior
20+
const multiEditor = createMultieditor(editor => ({
2121
data: {
22-
id: "myId", // Inital Id
22+
id: "myId", // Initial Id
2323
email: undefined, // Inital Email
24-
key: undefined, // Inital Name
24+
name: undefined, // Inital Name
2525
},
2626
onSubmit: async (data) => {
27-
console.log("Submitted ", data); // <-------------------------------------------
28-
}, // |
29-
fixedProperties: ["id"], // Properties that always get passed as data into the onSubmit function
27+
console.log("Submitted ", data); // <---------------------------------------------
28+
}, // |
29+
fixedProperties: ["id"], // Properties that are always passed to the 'onSubmit()' method
3030
validateMethods: {
31-
email: editor.Validator().string().email().required(), // Email is requiered, a string and follows the Email regex
32-
key: editor.Validator().string().max(10).min(2).required(), // Name is required, a string, has to be shorter than 10 and longer than 2 chars
31+
email: agileResolver(isString, isEmail, isRequired), // Validation with tree shakable validation methods
32+
name: yupResolver(Yup.string().max(10).min(2).required()), // Validation with external validatiors like Yup
3333
},
34-
editableProperties: ["email", "key"], // Properties that can be edited
34+
editableProperties: ["email", "name"], // Properties that can be edited
3535
}));
3636

37-
// Lets update the requiered properties to validate the Editor
37+
// Update Multieditor values in the UI-Form
3838
multiEditor.setValue("email", "test@test.com");
39-
multiEditor.setValue("key", "Jeff");
39+
multiEditor.setValue("name", "Jeff");
4040

41-
// Now we can submit the Editor and see what the onSubmit will log
41+
// Submit Multieditor and see what the 'onSubmit()' method will log
4242
multiEditor.submit();
4343
// Submited {
4444
// id: "myId",
45-
// key: "Jeff",
45+
// name: "Jeff",
4646
// email: "test@test.com"
4747
// }
4848
```
49-
_Do you want to see it in action? Click [here](https://codesandbox.io/s/multieditor-yxt4x)._
5049

50+
### ⛳️ Sandbox
51+
Test the Multieditor yourself in a [codesandbox](https://codesandbox.io/s/multieditor-yxt4x).
52+
It's only one click away. Just select your preferred Framework below.
5153

52-
## ❓ Why Agile MultiEditor
54+
- [React](https://codesandbox.io/s/multieditor-yxt4x)
5355

54-
#### 🚅 Straightforward
55-
Write minimalistic, boilerplate free code that captures your intent. <br />
56-
**For instance**
57-
- Simple Validation
58-
```ts
59-
// Email is requiered, a string and follows the Email regex
60-
EDITOR.Validator().string().email().required()
61-
```
62-
- Compute Value
63-
```ts
64-
// Force Name to be lowercase
65-
key: (value) => {
66-
return value.toLowerCase();
67-
}
68-
```
56+
More examples can be found in the [Example section](https://agile-ts.org/docs/examples).
6957

7058

71-
#### 🎯 Easy to Use
72-
Learn the powerful and simple tools of Agile MultiEditor in a short amount of time.
59+
## ❓ Why Multieditor
7360

61+
#### 🚅 Straightforward
62+
Write minimalistic, boilerplate-free code that captures your intent.
63+
```ts
64+
// Simple and tree shakable inbuilt validation
65+
agileResolver(isRequired, isString('custom error message'), isEmail);
66+
67+
// Easy integration with external validation libraries like Yup
68+
yupResolver(Yup.string().email());
69+
70+
// Easy value compution
71+
computeMethods: {
72+
name: (value) => {
73+
return value.toLowerCase();
74+
}
75+
}
76+
```
7477

75-
#### 🍃 Lightweight
76-
Agile Api has an unpacked size of [14.1kB](https://bundlephobia.com/result?p=@agile-ts/multieditor@0.0.6)
77-
and [0 external dependencies](https://www.npmjs.com/package/@agile-ts/multieditor).
78+
### 🤸‍ Flexible
79+
- Works in nearly any UI-Framework (currently supported are [React](https://reactjs.org/), [React-Native](https://reactnative.dev/) and [Vue](https://vuejs.org/)).
80+
- Surly behaves with the workflow that suits you best.
81+
- Has **0** external dependencies.
82+
83+
### ⚡️ Fast
84+
Minimizes the number of re-renders
85+
and validate computation.
7886

7987

8088
## ⬇️ Installation
@@ -88,10 +96,33 @@ Therefore, we have created a table which shows which versions fit together witho
8896

8997
| @agile-ts/multieditor | @agile-ts/core | NPM Version |
9098
| ----------------------| ----------------------- | ------------------------ |
91-
| v0.0.7+ | v0.0.7+ | v6+ |
92-
| v0.0.6 | v0.0.3 - v0.0.6 | v6+ |
99+
| v0.0.22+ | v0.2.5+ | v6+ |
100+
93101
_Other Versions aren't supported anymore_
94102

95103

96104
## 📄 Documentation
97-
The Agile MultiEditor Docs are located [here](https://agile-ts.org/docs/)
105+
Does the Multieditor sound interesting to you?
106+
Take a look at our **[documentation](https://agile-ts.org/docs/introduction)**,
107+
to learn more about its functionalities and capabilities.
108+
If you have any further questions,
109+
feel free to join our [Community Discord](https://discord.gg/T9GzreAwPH).
110+
We will be happy to help you.
111+
112+
113+
## 👨‍💻 Contribute
114+
Get a part of AgileTs and start contributing. We welcome any meaningful contribution. 😀
115+
To find out more about contributing, check out the [CONTRIBUTING.md](https://github.com/agile-ts/agile/blob/master/CONTRIBUTING.md).
116+
117+
<a href="https://codeclimate.com/github/agile-ts/agile/coverage.svg">
118+
<img src="https://codeclimate.com/github/agile-ts/agile/badges/gpa.svg" alt="Maintainability"/>
119+
</a>
120+
121+
### ♥️ Contributors
122+
123+
<a href="https://github.com/agile-ts/agile/graphs/contributors">
124+
<img src="https://contrib.rocks/image?repo=agile-ts/agile" />
125+
</a>
126+
127+
[Become a contributor](https://github.com/agile-ts/agile/blob/master/CONTRIBUTING.md)
128+

packages/multieditor/src/item.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
import {
2-
StateRuntimeJobConfigInterface,
3-
defineConfig,
4-
State,
5-
LogCodeManager,
6-
} from '@agile-ts/core';
1+
import { StateRuntimeJobConfigInterface, State } from '@agile-ts/core';
2+
import { isFunction, defineConfig } from '@agile-ts/utils';
73
import { ItemKey, Multieditor } from './multieditor';
84
import { Status } from './status';
95
import { Validator } from './validator';
10-
import { isFunction } from '@agile-ts/utils';
6+
import { LogCodeManager } from './logCodeManager';
117

128
export class Item<ValueType = any> extends State<ValueType> {
139
// Multieditor the Item belongs to
1410
public editor: () => Multieditor<ValueType>;
1511

1612
public config: ItemConfigInterface;
1713

18-
// Whether the Item is valid.
14+
// Whether the Item value is valid
1915
public isValid = false;
2016
// Handles the validation of the Item
2117
public validator: Validator<ValueType>;
22-
// Validation Status of the Item
18+
// Handles and represents the validation Status of the Item
2319
public status: Status;
2420

2521
// Method for dynamically computing the Item value
@@ -30,7 +26,7 @@ export class Item<ValueType = any> extends State<ValueType> {
3026
*
3127
* @public
3228
* @param editor - Multieditor to which the Item belongs.
33-
* @param initialValue - Data that the Item holds
29+
* @param initialValue - Initial value of the Item.
3430
* @param config - Configuration object
3531
*/
3632
constructor(
@@ -56,13 +52,16 @@ export class Item<ValueType = any> extends State<ValueType> {
5652

5753
if (this.editor().canAssignStatusToItemOnChange(this))
5854
this.status.display = true;
59-
this.editor().validate();
55+
56+
// Recompute Multieditor states
57+
this.editor().recomputeValidatedState({ validate: false });
6058
this.editor().recomputeModifiedState();
6159
});
6260
}
6361

6462
/**
65-
* Revalidates the Item.
63+
* Revalidates the Item via the Validator
64+
* and updates the 'isValid' state.
6665
*
6766
* @public
6867
*/
@@ -75,7 +74,6 @@ export class Item<ValueType = any> extends State<ValueType> {
7574
/**
7675
* Resets the Item value to its initial value.
7776
*
78-
*
7977
* @public
8078
* @param config - Configuration object
8179
*/
@@ -112,17 +110,17 @@ export class Item<ValueType = any> extends State<ValueType> {
112110

113111
export interface ItemConfigInterface {
114112
/**
115-
* Key/Name identifier of the State.
113+
* Key/Name identifier of the Item.
116114
*/
117115
key: ItemKey;
118116
/**
119117
* Whether the Item value can be edited
120-
* and thus is passes into the 'preparedData' object when submitting.
118+
* and thus should be represented in the 'preparedData' object when submitting.
121119
* @default true
122120
*/
123121
canBeEdited?: boolean;
124122
/**
125-
* Validator to handle the validation of the Item.
123+
* Validator to handle validating the Item.
126124
* @default newly create Validator
127125
*/
128126
validator?: Validator;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {
2+
LogCodeManager as CoreLogCodeManager,
3+
assignAdditionalLogs,
4+
} from '@agile-ts/core';
5+
6+
const additionalLogs = {
7+
// Validator
8+
'41:03:00': "A validation method needs to be of the type 'function'!",
9+
'41:03:01': "Appending a Validator to itself isn't allowed!",
10+
};
11+
12+
/**
13+
* The Log Code Manager keeps track
14+
* and manages all important Logs for the '@agile-ts/multieditor' package.
15+
*
16+
* @internal
17+
*/
18+
export const LogCodeManager =
19+
process.env.NODE_ENV !== 'production'
20+
? assignAdditionalLogs<
21+
typeof CoreLogCodeManager.logCodeMessages & typeof additionalLogs
22+
>(additionalLogs, CoreLogCodeManager)
23+
: assignAdditionalLogs<
24+
typeof CoreLogCodeManager.logCodeMessages & typeof additionalLogs
25+
>({}, CoreLogCodeManager);

packages/multieditor/src/multieditor/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import { EditorConfig, Multieditor } from './multieditor';
33

44
export * from './multieditor';
55

6+
/**
7+
* Returns a newly created Multieditor.
8+
*
9+
* A Multieditor is a simple Form Handler.
10+
*
11+
* @public
12+
* @param config - Configuration object
13+
* @param agileInstance - Instance of Agile the Multieditor belongs to.
14+
*/
615
export function createMultieditor<
716
DataType = any,
817
SubmitReturnType = void,

0 commit comments

Comments
 (0)