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

Commit 2af9de8

Browse files
committed
removed tries to modularize the react package
1 parent e6e9b0e commit 2af9de8

File tree

22 files changed

+112
-66
lines changed

22 files changed

+112
-66
lines changed

examples/react/develop/functional-component-ts/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect } from 'react';
22
import './App.css';
33
import { useAgile, useWatcher, useSelector } from '@agile-ts/react';
4-
import { useProxy } from '@agile-ts/react/proxy';
4+
import { useProxy } from '@agile-ts/react';
55
import {
66
COUNTUP,
77
externalCreatedItem,

packages/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"watch:push": "tsc-watch --onSuccess \"yarn run dev:push\"",
3333
"watch": "shx rm -rf dist && tsc -w",
3434
"release": "yarn run prepare",
35-
"release:manual": "yarn run prepare && yarn run release && npm publish",
35+
"release:manual": "yarn run release && npm publish",
3636
"pack": "npm pack",
3737
"test": "jest",
3838
"test:coverage": "jest --coverage",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"watch:push": "tsc-watch --onSuccess \"yarn run dev:push\"",
4444
"watch": "shx rm -rf dist && tsc -w",
4545
"release": "node ./scripts/prepublish.js && yarn run prepare",
46-
"release:manual": "yarn run prepare && yarn run release && npm publish && git checkout README.md",
46+
"release:manual": "yarn run release && npm publish && git checkout README.md",
4747
"pack": "npm pack",
4848
"test": "jest",
4949
"test:coverage": "jest --coverage",

packages/core/scripts/prepublish.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
const fs = require('fs-extra');
2-
const path = require('path');
3-
const execa = require('execa');
42

53
const run = () => {
64
fs.copySync('../../README.md', './README.md');

packages/core/src/logCodeManager.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,10 @@ function setAllowLogging(logging: boolean) {
185185
* @param replacers - Instances that replace these '${x}' placeholders based on the index
186186
* For example: 'replacers[0]' replaces '${0}', 'replacers[1]' replaces '${1}', ..
187187
*/
188-
function getLog<T extends LogCodesArrayType<typeof logCodeMessages>>(
189-
logCode: T,
190-
replacers: any[] = []
191-
): string {
192-
let result = logCodeMessages[logCode];
188+
function getLog<
189+
T extends LogCodesArrayType<typeof LogCodeManager.logCodeMessages>
190+
>(logCode: T, replacers: any[] = []): string {
191+
let result = LogCodeManager.logCodeMessages[logCode];
193192
if (result == null) return logCode;
194193

195194
// Replace '${x}' with the specified replacer instances
@@ -210,11 +209,9 @@ function getLog<T extends LogCodesArrayType<typeof logCodeMessages>>(
210209
* For example: 'replacers[0]' replaces '${0}', 'replacers[1]' replaces '${1}', ..
211210
* @param data - Data to be attached to the end of the log message.
212211
*/
213-
function log<T extends LogCodesArrayType<typeof logCodeMessages>>(
214-
logCode: T,
215-
replacers: any[] = [],
216-
...data: any[]
217-
): void {
212+
function log<
213+
T extends LogCodesArrayType<typeof LogCodeManager.logCodeMessages>
214+
>(logCode: T, replacers: any[] = [], ...data: any[]): void {
218215
const logger = LogCodeManager.getLogger();
219216
if ((logger != null && !logger.isActive) || !allowLogging) return;
220217
const logType = logCodeTypes[logCode.substr(3, 2)];
@@ -242,15 +239,12 @@ function log<T extends LogCodesArrayType<typeof logCodeMessages>>(
242239
* For example: 'replacers[0]' replaces '${0}', 'replacers[1]' replaces '${1}', ..
243240
* @param data - Data to be attached to the end of the log message.
244241
*/
245-
function logIfTags<T extends LogCodesArrayType<typeof logCodeMessages>>(
246-
tags: string[],
247-
logCode: T,
248-
replacers: any[] = [],
249-
...data: any[]
250-
): void {
242+
function logIfTags<
243+
T extends LogCodesArrayType<typeof LogCodeManager.logCodeMessages>
244+
>(tags: string[], logCode: T, replacers: any[] = [], ...data: any[]): void {
251245
const logger = LogCodeManager.getLogger();
252246
if ((logger != null && !logger.isActive) || !allowLogging) return;
253-
const logType = logCodeTypes[logCode.substr(3, 2)];
247+
const logType = LogCodeManager.logCodeLogTypes[logCode.substr(3, 2)];
254248
if (typeof logType !== 'string') return;
255249

256250
// Handle logging without Logger
@@ -267,15 +261,15 @@ function logIfTags<T extends LogCodesArrayType<typeof logCodeMessages>>(
267261
* Creates an extension of the specified LogCodeManager
268262
* and assigns the provided additional log messages to it.
269263
*
270-
* @param additionalLogs - Log messages to be added to the LogCodeManager.
271264
* @param logCodeManager - LogCodeManager to create an extension from.
265+
* @param additionalLogs - Log messages to be added to the LogCodeManager.
272266
*/
273267
export function assignAdditionalLogs<
274268
NewLogCodeMessages,
275-
OldLogCodeMessages = typeof logCodeMessages
269+
OldLogCodeMessages = typeof LogCodeManager.logCodeMessages
276270
>(
277-
additionalLogs: { [key: string]: string },
278-
logCodeManager: LogCodeManagerInterface<OldLogCodeMessages>
271+
logCodeManager: LogCodeManagerInterface<OldLogCodeMessages>,
272+
additionalLogs: { [key: string]: string }
279273
): LogCodeManagerInterface<NewLogCodeMessages> {
280274
const copiedLogCodeManager = copy(logCodeManager);
281275
copiedLogCodeManager.logCodeMessages = {

packages/event/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"watch:push": "tsc-watch --onSuccess \"yarn run dev:push\"",
3232
"watch": "shx rm -rf dist && tsc -w",
3333
"release": "yarn run prepare",
34-
"release:manual": "yarn run prepare && yarn run release && npm publish",
34+
"release:manual": "yarn run release && npm publish",
3535
"pack": "npm pack",
3636
"test": "jest",
3737
"test:coverage": "jest --coverage",

packages/logger/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"watch:push": "tsc-watch --onSuccess \"yarn run dev:push\"",
3232
"watch": "shx rm -rf dist && tsc -w",
3333
"release": "yarn run prepare",
34-
"release:manual": "yarn run prepare && yarn run release && npm publish",
34+
"release:manual": "yarn run release && npm publish",
3535
"pack": "npm pack",
3636
"test": "jest",
3737
"test:coverage": "jest --coverage",

packages/multieditor/README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,33 @@
1818
```ts
1919
// Create Multieditior
2020
const multiEditor = createMultieditor(editor => ({
21-
data: {
21+
initialData: {
2222
id: "myId", // Initial Id
2323
email: undefined, // Inital Email
2424
name: undefined, // Inital Name
2525
},
2626
onSubmit: async (data) => {
27-
console.log("Submitted ", data); // <---------------------------------------------
28-
}, // |
29-
fixedProperties: ["id"], // Properties that are always passed to the 'onSubmit()' method
30-
validateMethods: {
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
33-
},
34-
editableProperties: ["email", "name"], // Properties that can be edited
27+
console.log("Submitted ", data); // <---------
28+
}, // |
29+
// Properties that are always passed to the 'onSubmit()' method
30+
fixedProperties: ["id"],
31+
validationSchema: {
32+
// Validation with inbuilt tree shakable validation methods
33+
email: agileResolver(isString, isEmail, isRequired),
34+
// Validation with external validatiors like Yup
35+
name: yupResolver(Yup.string().required().max(10).min(2)),
36+
}
3537
}));
3638

37-
// Update Multieditor values in the UI-Form
38-
multiEditor.setValue("email", "[email protected]");
39-
multiEditor.setValue("name", "Jeff");
39+
// Use the Multieditor in any UI-Form
40+
// ..
41+
<label>First Name:</label>
42+
<input
43+
onChange={(e) => signUpEditor.setValue("firstName", e.target.value)}
44+
defaultValue={signUpEditor.getItemInitialValue("firstName")}
45+
/>
46+
<ErrorMessage error={signUpEditor.getStatus("firstName")?.message} />
47+
// ..
4048

4149
// Submit Multieditor and see what the 'onSubmit()' method will log
4250
multiEditor.submit();

packages/multieditor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"watch:push": "tsc-watch --onSuccess \"yarn run dev:push\"",
3636
"watch": "shx rm -rf dist && tsc -w",
3737
"release": "yarn run prepare",
38-
"release:manual": "yarn run prepare && yarn run release && npm publish",
38+
"release:manual": "yarn run release && npm publish",
3939
"pack": "npm pack",
4040
"test": "jest",
4141
"test:coverage": "jest --coverage",

packages/multieditor/src/logCodeManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const LogCodeManager =
1919
process.env.NODE_ENV !== 'production'
2020
? assignAdditionalLogs<
2121
typeof CoreLogCodeManager.logCodeMessages & typeof additionalLogs
22-
>(additionalLogs, CoreLogCodeManager)
22+
>(CoreLogCodeManager, additionalLogs)
2323
: assignAdditionalLogs<
2424
typeof CoreLogCodeManager.logCodeMessages & typeof additionalLogs
25-
>({}, CoreLogCodeManager);
25+
>(CoreLogCodeManager, {});

packages/proxytree/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"watch:push": "tsc-watch --onSuccess \"yarn run dev:push\"",
3232
"watch": "shx rm -rf dist && tsc -w",
3333
"release": "yarn run prepare",
34-
"release:manual": "yarn run prepare && yarn run release && npm publish",
34+
"release:manual": "yarn run release && npm publish",
3535
"pack": "npm pack",
3636
"test": "jest",
3737
"test:coverage": "jest --coverage",

packages/react/package.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@
3232
"module": "./dist/esm/index.js",
3333
"import": "./dist/esm/index.js",
3434
"default": "./dist/index.js"
35+
},
36+
"./proxy": {
37+
"types": "./dist/proxy/index.d.ts",
38+
"module": "./dist/esm/proxy/index.js",
39+
"import": "./dist/esm/proxy/index.js",
40+
"default": "./dist/proxy/index.js"
41+
},
42+
"./event": {
43+
"types": "./dist/event/index.d.ts",
44+
"module": "./dist/esm/event/index.js",
45+
"import": "./dist/esm/event/index.js",
46+
"default": "./dist/event/index.js"
47+
},
48+
"./multieditor": {
49+
"types": "./dist/multieditor/index.d.ts",
50+
"module": "./dist/esm/multieditor/index.js",
51+
"import": "./dist/esm/multieditor/index.js",
52+
"default": "./dist/multieditor/index.js"
3553
}
3654
},
3755
"scripts": {
@@ -42,7 +60,7 @@
4260
"watch:push": "tsc-watch --onSuccess \"yarn run dev:push\"",
4361
"watch": "shx rm -rf dist && tsc -w",
4462
"release": "yarn run prepare",
45-
"release:manual": "yarn run prepare && yarn run release && npm publish",
63+
"release:manual": "yarn run release && npm publish",
4664
"pack": "npm pack",
4765
"test": "jest",
4866
"test:coverage": "jest --coverage",

packages/react/src/core/hooks/useBaseAgile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Agile, {
88
SubscriptionContainerKeyType,
99
RegisterSubscriptionConfigInterface,
1010
} from '@agile-ts/core';
11-
import { useIsomorphicLayoutEffect } from '../../general/hooks/useIsomorphicLayoutEffect';
11+
import { useIsomorphicLayoutEffect } from '../../general';
1212
import { LogCodeManager } from '../../logCodeManager';
1313

1414
/**
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// TODO https://stackoverflow.com/questions/68148235/require-module-inside-a-function-doesnt-work
2+
export let eventPackage: any = null;
3+
try {
4+
eventPackage = require('@agile-ts/event');
5+
} catch (e) {
6+
// empty catch block
7+
}

packages/react/src/event/hooks/useEvent.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@ import React from 'react';
22
import {
33
Agile,
44
getAgileInstance,
5-
LogCodeManager,
65
SubscriptionContainerKeyType,
76
} from '@agile-ts/core';
8-
import { Event, EventCallbackFunction } from '@agile-ts/event';
7+
import type { Event, EventCallbackFunction } from '@agile-ts/event'; // When only importing the types the "Can't resolve '@agile-ts/event'" error doesn't occur
98
import { useIsomorphicLayoutEffect } from '../../general';
9+
import { eventPackage } from '../eventPackage';
10+
import { LogCodeManager } from '../../logCodeManager';
1011

1112
export function useEvent<E extends Event<any>>(
1213
event: E,
1314
callback: EventCallbackFunction<E['payload']>,
1415
key?: SubscriptionContainerKeyType,
1516
agileInstance?: Agile
1617
): void {
18+
// Return if '@agile-ts/event' isn't installed
19+
if (eventPackage == null) {
20+
LogCodeManager.log('33:03:00');
21+
return;
22+
}
23+
1724
// Trigger State used to force Component to rerender
1825
const [, forceRender] = React.useReducer((s) => s + 1, 0);
1926

packages/react/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import reactIntegration from './react.integration';
22

33
export * from './core';
4+
export * from './proxy';
5+
export * from './event';
46

57
export default reactIntegration;

packages/react/src/logCodeManager.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const additionalLogs = {
99
'31:03:00':
1010
"In order to use the Agile proxy functionality, the installation of an additional package called '@agile-ts/proxytree' is required!",
1111
'32:03:00': 'Failed to subscribe Component with deps',
12+
'33:03:00':
13+
"In order to use the Agile event functionality, the installation of an additional package called '@agile-ts/event' is required!",
1214
};
1315

1416
/**
@@ -21,7 +23,9 @@ export const LogCodeManager =
2123
process.env.NODE_ENV !== 'production'
2224
? assignAdditionalLogs<
2325
typeof CoreLogCodeManager.logCodeMessages & typeof additionalLogs
24-
>(additionalLogs, CoreLogCodeManager)
26+
>(CoreLogCodeManager, additionalLogs)
2527
: assignAdditionalLogs<
2628
typeof CoreLogCodeManager.logCodeMessages & typeof additionalLogs
27-
>({}, CoreLogCodeManager);
29+
>(CoreLogCodeManager, {});
30+
31+
console.log(LogCodeManager);

packages/react/src/proxy/hooks/useProxy.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
ProxyWeakMapType,
66
} from '@agile-ts/core';
77
import { generateId, isValidObject, normalizeArray } from '@agile-ts/utils';
8-
import { ProxyTree } from '@agile-ts/proxytree';
98
import {
109
AgileHookConfigInterface,
1110
AgileOutputHookArrayType,
@@ -14,6 +13,8 @@ import {
1413
SubscribableAgileInstancesType,
1514
useBaseAgile,
1615
} from '../../core';
16+
import { proxyPackage } from '../proxyPackage';
17+
import { LogCodeManager } from '../../logCodeManager';
1718

1819
/**
1920
* A React Hook for binding the most relevant value of multiple Agile Instances
@@ -78,14 +79,20 @@ export function useProxy<
7879
const depsArray = extractRelevantObservers(normalizeArray(deps));
7980
const proxyTreeWeakMap = new WeakMap();
8081

82+
// Return if '@agile-ts/proxytree' isn't installed
83+
if (proxyPackage == null) {
84+
LogCodeManager.log('31:03:00');
85+
return null as any;
86+
}
87+
8188
const handleReturn = (dep: Observer | undefined) => {
8289
if (dep == null) return undefined as any;
8390
const value = dep.value;
8491

8592
// If proxyBased and the value is of the type object.
8693
// Wrap a Proxy around the object to track the accessed properties.
8794
if (isValidObject(value, true)) {
88-
const proxyTree = new ProxyTree(value);
95+
const proxyTree = new proxyPackage.ProxyTree(value);
8996
proxyTreeWeakMap.set(dep, proxyTree);
9097
return proxyTree.proxy;
9198
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// TODO https://stackoverflow.com/questions/68148235/require-module-inside-a-function-doesnt-work
2+
export let proxyPackage: any = null;
3+
try {
4+
proxyPackage = require('@agile-ts/proxytree');
5+
} catch (e) {
6+
// empty catch block
7+
}

packages/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"watch:push": "tsc-watch --onSuccess \"yarn run dev:push\"",
3131
"watch": "shx rm -rf dist && tsc -w",
3232
"release": "yarn run prepare",
33-
"release:manual": "yarn run prepare && yarn run release && npm publish",
33+
"release:manual": "yarn run release && npm publish",
3434
"pack": "npm pack",
3535
"test": "jest",
3636
"test:coverage": "jest --coverage",

packages/vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"watch:push": "tsc-watch --onSuccess \"yarn run dev:push\"",
3434
"watch": "shx rm -rf dist && tsc -w",
3535
"release": "yarn run prepare",
36-
"release:manual": "yarn run prepare && yarn run release && npm publish",
36+
"release:manual": "yarn run release && npm publish",
3737
"pack": "npm pack",
3838
"test": "jest",
3939
"test:coverage": "jest --coverage",

0 commit comments

Comments
 (0)