diff --git a/.changeset/warm-terms-help.md b/.changeset/warm-terms-help.md
new file mode 100644
index 00000000..29dfedf2
--- /dev/null
+++ b/.changeset/warm-terms-help.md
@@ -0,0 +1,11 @@
+---
+'@agile-ts/api': patch
+'@agile-ts/core': patch
+'cra-template-agile': patch
+'cra-template-agile-typescript': patch
+'@agile-ts/event': patch
+'@agile-ts/multieditor': patch
+'@agile-ts/react': patch
+---
+
+fixed bugs and increased versions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 6ffe2f3a..0d5b1734 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -75,17 +75,17 @@ Don't take this personally if this happens, and feel free to open a new issue on
## ⏳ Installation
1. Ensure you have [Yarn](https://yarnpkg.com/) installed
-2. After cloning the repository, run `yarn run install-packages` in the root of the repository,
+2. After cloning the repository, run `yarn run install:agile` in the root of the repository,
which simply runs `yarn install` in each package to ensure all dependencies are installed.
### Run Example Project's
1. Follow the [Installation](#Installation) steps above
2. Ensure you have [Yalc](https://www.google.com/search?client=firefox-b-d&q=yalc) installed
-3. Run `yarn run dev-publish` to publish all packages in your local 'npm store'
+3. Run `yarn run dev:publish` to publish all packages in your local 'npm store'
4. Execute `yarn install` in the Example Project to install its dependencies like AgileTs
-5. If you made your desired changes. Run `yarn run dev-push` to push your updated changes into your local 'npm store'
- _ProTip:_ To make realtime changes, run `yarn run watch`, which automatically runs `yarn run dev-push` everytime you update a file in a package.
+5. If you made your desired changes. Run `yarn run dev:push` to push your updated changes into your local 'npm store'
+ _ProTip:_ To make realtime changes, run `yarn run watch`, which automatically runs `yarn run dev:push` everytime you update a file in a package.
## ☄️ Pull Request
diff --git a/README.md b/README.md
index dd28e64c..e8fbde70 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
- > **AgileTs is a spacy, fast, simple State Management Framework**
+ > Global, simple, spacy State and Logic Framework
@@ -29,7 +29,7 @@
-
+
@@ -55,7 +55,7 @@ const MY_FIRST_STATE = App.createState("Hello Stranger!");
// And wolla its reactive. Everytime the State mutates the Component gets rerendered
const myFirstState = useAgile(MY_FIRST_STATE); // returns value of State ("Hello Stranger!")
```
-To find out more checkout our [documentation](https://agile-ts.org/docs/installation).
+To find out more checkout our [documentation](https://agile-ts.org/docs/introduction).
### ⛳️ Sandbox
Test AgileTs yourself, it's only one click away. Just select your preferred Framework below.
@@ -63,7 +63,7 @@ Test AgileTs yourself, it's only one click away. Just select your preferred Fram
- Vue (coming soon)
- Angular (coming soon)
-More examples can be found in the [Example Section](../examples/Indroduction.md).
+More examples can be found in the [Example Section](https://agile-ts.org/docs/examples).
@@ -72,10 +72,9 @@ More examples can be found in the [Example Section](../examples/Indroduction.md)
-AgileTs is a simple, fast and well tested State Management Framework which is implemented in TypeScript.
-It's more flexible and boilerplate free than Redux and has an interesting approach to reducing
-the size of a codebase through a centralized memory design pattern.
-The philosophy behind AgileTs is simple:
+AgileTs is a global, simple, well-tested State Management Framework implemented in TypeScript.
+It's more flexible and boilerplate-free than frameworks like Redux and has a powerful approach to reducing the codebase size through a
+centralized memory design pattern. The philosophy behind AgileTs is simple:
### 🚅 Straightforward
Write minimalistic, boilerplate free code that captures your intent.
@@ -91,22 +90,21 @@ Write minimalistic, boilerplate free code that captures your intent.
MY_COLLECTION.collect({id: 1, name: "Frank"});
MY_COLLECTION.collect({id: 2, name: "Dieter"});
```
-- Mutate or Check States with simple Functions
+- Mutate and Check States with simple Functions
```ts
MY_STATE.undo(); // Undo latest change
MY_STATE.is({hello: "jeff"}); // Check if State has the Value '{hello: "jeff"}'
```
### 🤸 Flexible
-- Works in nearly every UI-Framework. Check [here](https://agile-ts.org/docs/frameworks) if your preferred framework is supported too.
-- Surly behaves with the workflow that suits you best.
- No need for _reducers_, _actions_, ..
-- Has **no** external dependencies
+- Works in nearly any UI-Layer. Check [here](https://agile-ts.org/docs/frameworks) if your preferred Framework is supported too.
+- Surly behaves with the workflow which suits you best. No need boilerplate code.
+- Has **0** external dependencies
### 🎯 Easy to Use
Learn the powerful tools of AgileTs in a short amount of time.
-A good place to start are our [Quick Starts](./Installation.md)
-or if you are no fan of following any tutorial, checkout your [examples](../examples).
+A good place to start are our [Quick Start Guides](https://agile-ts.org/docs/installation)
+or if you are no fan of following any tutorial, checkout your [Examples](https://agile-ts.org/docs/examples).
@@ -115,15 +113,15 @@ or if you are no fan of following any tutorial, checkout your [examples](../exam
-To properly use AgileTs, in a UI-Framework we need **two** packages.
+To properly use AgileTs, in a UI-Framework we need to install **two** packages.
- The _Core Package_, which acts as the brain of AgileTs and manages all our States
```
npm install @agile-ts/core
```
-- and a _fitting Integration_ for our preferd UI-Framework.. in my case the [React Integration](https://www.npmjs.com/package/@agile-ts/react).
- Check [here](https://agile-ts.org/docs/installation) if your desired Framework is supported, too.
+- and a _fitting Integration_ for our preferd UI-Framework. In my case the [React Integration](https://www.npmjs.com/package/@agile-ts/react).
+ Check [here](https://agile-ts.org/docs/frameworks) if your desired Framework is supported, too.
```
npm install @agile-ts/react
```
@@ -135,10 +133,10 @@ To properly use AgileTs, in a UI-Framework we need **two** packages.
-If AgileTs sounds interesting to you.
-Checkout our **[docs](https://agile-ts.org/docs/)**.
-And I am sure you will be able to use it in no time.
-In case you have any questions don't mind joining our [Discord Community](https://discord.gg/FTqeMNCxw7).
+Sounds AgileTs interesting to you?
+Checkout our **[documentation](https://agile-ts.org/docs/introduction)**, to learn more.
+And I promise you, you will be able to use AgileTs in no time.
+In case you have any further questions don't mind joining our [Community Discord](https://discord.gg/T9GzreAwPH).
@@ -147,9 +145,8 @@ In case you have any questions don't mind joining our [Discord Community](https:
-Get a part of AgileTs and start contributing.
+Get a part of AgileTs and start contributing. We welcome any meaningful contribution 😀
To find out more checkout the [CONTRIBUTING.md](https://github.com/agile-ts/agile/blob/master/CONTRIBUTING.md).
-We welcome any meaningful contribution 😀
@@ -168,6 +165,7 @@ We welcome any meaningful contribution 😀
| [@agile-ts/react](/packages/react) | [](https://www.npmjs.com/package/@agile-ts/react) | React Integration |
| [@agile-ts/api](/packages/api) | [](https://www.npmjs.com/package/@agile-ts/api) | Promise based Api |
| [@agile-ts/multieditor](/packages/multieditor) | [](https://www.npmjs.com/package/@agile-ts/multieditor) | Simple Form Manager |
+| [@agile-ts/event](/packages/event) | [](https://www.npmjs.com/package/@agile-ts/event) | Handy class for emitting UI Events |
@@ -176,5 +174,5 @@ We welcome any meaningful contribution 😀
-AgileTs is inspired by MVVM frameworks like [MobX](https://mobx.js.org/README.html) and [PulseJs](https://github.com/pulse-framework/pulse).
+AgileTs is inspired by [MVVM Frameworks](https://de.wikipedia.org/wiki/Model_View_ViewModel) like [MobX](https://mobx.js.org/README.html) and [PulseJs](https://github.com/pulse-framework/pulse).
diff --git a/examples/react-native/AwesomeTSProject/README.md b/examples/react-native/AwesomeTSProject/README.md
index 3813517e..7fe35f54 100644
--- a/examples/react-native/AwesomeTSProject/README.md
+++ b/examples/react-native/AwesomeTSProject/README.md
@@ -14,18 +14,18 @@ This Example represents the basic features of the `core` package in a **function
#### 1. Run `npm install` at the root of Agile
At first, we have to install some 'global' dependencies of AgileTs.
-#### 2. Run `npm run install-all` at the root of Agile
+#### 2. Run `npm run install:agile` at the root of Agile
Then we install the dependencies of all AgileTs Packages (core, react, api, ..)
-#### 3. Run `npm run dev-publish` at the root of Agile
+#### 3. Run `npm run dev:publish` at the root of Agile
As next step we `publish` all AgileTs Packages to our local `yalc` repository,
to import them later in our examples.
-#### 4. Run `npm run install-agile` in this Project
+#### 4. Run `npm run install:agile` in this Project
To run the example we have to install the dependencies of it, too.
We aren't using `npm install`, because we want to add the just published AgileTs Packages properly.
-#### 5. Run `npm run dev-push` at the root of Agile
+#### 5. Run `npm run dev:push` at the root of Agile
After 'publishing' the AgileTs Packages and installing the dependencies of the example, we can push our changes,
which we might have made for instance in the core package, to yalc by running this command.
All projects having a dependency of the pushed package will receive the changes immediately.
diff --git a/examples/react-native/AwesomeTSProject/core/index.ts b/examples/react-native/AwesomeTSProject/core/index.ts
index 3e5f1e2c..011ceb0e 100644
--- a/examples/react-native/AwesomeTSProject/core/index.ts
+++ b/examples/react-native/AwesomeTSProject/core/index.ts
@@ -1,4 +1,5 @@
import { Agile } from '@agile-ts/core';
+import { Event } from '@agile-ts/event';
import { Alert } from 'react-native';
export const App = new Agile({
@@ -42,7 +43,7 @@ MY_COLLECTION.getGroup('myGroup')?.persist({
console.log('Initial: myCollection ', MY_COLLECTION);
-export const MY_EVENT = App.createEvent<{ name: string }>();
+export const MY_EVENT = new Event<{ name: string }>(App);
MY_EVENT.on('Test', (payload) => {
Alert.alert(
diff --git a/examples/react-native/AwesomeTSProject/package.json b/examples/react-native/AwesomeTSProject/package.json
index 2b944aa8..70fffb4f 100644
--- a/examples/react-native/AwesomeTSProject/package.json
+++ b/examples/react-native/AwesomeTSProject/package.json
@@ -8,12 +8,13 @@
"start": "react-native start",
"test": "jest",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
- "install-agile": "yalc add @agile-ts/core @agile-ts/react @agile-ts/api & yarn install"
+ "install:agile": "yalc add @agile-ts/core @agile-ts/react @agile-ts/api & yarn install"
},
"dependencies": {
"@agile-ts/api": "file:.yalc/@agile-ts/api",
"@agile-ts/core": "file:.yalc/@agile-ts/core",
"@agile-ts/react": "file:.yalc/@agile-ts/react",
+ "@agile-ts/event": "file:.yalc/@agile-ts/event",
"react": "16.13.1",
"react-native": "0.63.3"
},
diff --git a/examples/react/class-component-ts/README.md b/examples/react/class-component-ts/README.md
index 5c81f6c1..be435310 100644
--- a/examples/react/class-component-ts/README.md
+++ b/examples/react/class-component-ts/README.md
@@ -14,18 +14,18 @@ This Example represents the basic features of the `core` package in a **class co
#### 1. Run `npm install` at the root of Agile
At first, we have to install some 'global' dependencies of AgileTs.
-#### 2. Run `npm run install-all` at the root of Agile
+#### 2. Run `npm run install:agile` at the root of Agile
Then we install the dependencies of all AgileTs Packages (core, react, api, ..)
-#### 3. Run `npm run dev-publish` at the root of Agile
+#### 3. Run `npm run dev:publish` at the root of Agile
As next step we `publish` all AgileTs Packages to our local `yalc` repository,
to import them later in our examples.
-#### 4. Run `npm run install-agile` in this Project
+#### 4. Run `npm run install:agile` in this Project
To run the example we have to install the dependencies of it, too.
We aren't using `npm install`, because we want to add the just published AgileTs Packages properly.
-#### 5. Run `npm run dev-push` at the root of Agile
+#### 5. Run `npm run dev:push` at the root of Agile
After 'publishing' the AgileTs Packages and installing the dependencies of the example, we can push our changes,
which we might have made for instance in the core package, to yalc by running this command.
All projects having a dependency of the pushed package will receive the changes immediately.
diff --git a/examples/react/class-component-ts/package.json b/examples/react/class-component-ts/package.json
index 6cb357be..dbd9687f 100644
--- a/examples/react/class-component-ts/package.json
+++ b/examples/react/class-component-ts/package.json
@@ -28,7 +28,7 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
- "install-agile": "yalc add @agile-ts/core @agile-ts/react @agile-ts/api @agile-ts/multieditor & yarn install"
+ "install:agile": "yalc add @agile-ts/core @agile-ts/react @agile-ts/api @agile-ts/multieditor @agile-ts/event & yarn install"
},
"eslintConfig": {
"extends": "react-app"
diff --git a/examples/react/functional-component-ts/README.md b/examples/react/functional-component-ts/README.md
index 17950747..2b0f7343 100644
--- a/examples/react/functional-component-ts/README.md
+++ b/examples/react/functional-component-ts/README.md
@@ -14,18 +14,18 @@ This Example represents the basic features of the `core` package in a **function
#### 1. Run `npm install` at the root of Agile
At first, we have to install some 'global' dependencies of AgileTs.
-#### 2. Run `npm run install-all` at the root of Agile
+#### 2. Run `npm run install:agile` at the root of Agile
Then we install the dependencies of all AgileTs Packages (core, react, api, ..)
-#### 3. Run `npm run dev-publish` at the root of Agile
+#### 3. Run `npm run dev:publish` at the root of Agile
As next step we `publish` all AgileTs Packages to our local `yalc` repository,
to import them later in our examples.
-#### 4. Run `npm run install-agile` in this Project
+#### 4. Run `npm run install:agile` in this Project
To run the example we have to install the dependencies of it, too.
We aren't using `npm install`, because we want to add the just published AgileTs Packages properly.
-#### 5. Run `npm run dev-push` at the root of Agile
+#### 5. Run `npm run dev:push` at the root of Agile
After 'publishing' the AgileTs Packages and installing the dependencies of the example, we can push our changes,
which we might have made for instance in the core package, to yalc by running this command.
All projects having a dependency of the pushed package will receive the changes immediately.
diff --git a/examples/react/functional-component-ts/package.json b/examples/react/functional-component-ts/package.json
index 7d73327f..c9627edb 100644
--- a/examples/react/functional-component-ts/package.json
+++ b/examples/react/functional-component-ts/package.json
@@ -7,6 +7,7 @@
"@agile-ts/core": "file:.yalc/@agile-ts/core",
"@agile-ts/multieditor": "file:.yalc/@agile-ts/multieditor",
"@agile-ts/react": "file:.yalc/@agile-ts/react",
+ "@agile-ts/event": "file:.yalc/@agile-ts/event",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
@@ -28,7 +29,7 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
- "install-agile": "yalc add @agile-ts/core @agile-ts/react @agile-ts/api @agile-ts/multieditor & yarn install"
+ "install:agile": "yalc add @agile-ts/core @agile-ts/react @agile-ts/api @agile-ts/multieditor @agile-ts/event & yarn install"
},
"eslintConfig": {
"extends": "react-app"
diff --git a/examples/react/functional-component-ts/src/App.tsx b/examples/react/functional-component-ts/src/App.tsx
index ceafc704..229611ef 100644
--- a/examples/react/functional-component-ts/src/App.tsx
+++ b/examples/react/functional-component-ts/src/App.tsx
@@ -1,6 +1,7 @@
import React, { useEffect } from 'react';
import './App.css';
-import { useAgile, useEvent, useWatcher } from '@agile-ts/react';
+import { useAgile, useWatcher } from '@agile-ts/react';
+import { useEvent } from '@agile-ts/event';
import {
MY_COLLECTION,
MY_COMPUTED,
diff --git a/examples/react/functional-component-ts/src/core/index.ts b/examples/react/functional-component-ts/src/core/index.ts
index d28c88da..c3fa7e91 100644
--- a/examples/react/functional-component-ts/src/core/index.ts
+++ b/examples/react/functional-component-ts/src/core/index.ts
@@ -1,4 +1,6 @@
import { Agile, clone, Logger } from '@agile-ts/core';
+import API from '@agile-ts/api';
+import Event from '@agile-ts/event';
export const App = new Agile({
logConfig: { level: Logger.level.DEBUG },
@@ -50,7 +52,7 @@ MY_COLLECTION.onLoad(() => {
console.log('Initial: myCollection ', clone(MY_COLLECTION));
-export const MY_EVENT = App.createEvent<{ name: string }>({
+export const MY_EVENT = new Event<{ name: string }>(App, {
delay: 3000,
key: 'myEvent',
});
@@ -94,3 +96,24 @@ logger.trace('This is a Trace');
logger.if.tag(['coreWarning']).warn('My core Warning');
logger.if.tag(['randomDebug']).debug('My random Debug');
logger.table('Test Table', { test: 'test', test1: 'test1' });
+
+const api = new API({
+ timeout: 10000,
+ options: {
+ credentials: undefined,
+ },
+});
+
+// testing some urls
+api
+ .with({
+ baseURL: `https://api.npmjs.org/downloads/point/2020-08-24:2020-09-24/@agile-ts/core`,
+ })
+ .get('');
+
+// testing some urls
+api
+ .with({
+ baseURL: `https://api`,
+ })
+ .get('');
diff --git a/examples/react/functional-component-ts/yarn.lock b/examples/react/functional-component-ts/yarn.lock
index 4c0a4379..dbc7bc96 100644
--- a/examples/react/functional-component-ts/yarn.lock
+++ b/examples/react/functional-component-ts/yarn.lock
@@ -3,16 +3,19 @@
"@agile-ts/api@file:.yalc/@agile-ts/api":
- version "0.0.11"
+ version "0.0.13"
"@agile-ts/core@file:.yalc/@agile-ts/core":
- version "0.0.11"
+ version "0.0.12"
+
+"@agile-ts/event@file:.yalc/@agile-ts/event":
+ version "0.0.1"
"@agile-ts/multieditor@file:.yalc/@agile-ts/multieditor":
- version "0.0.11"
+ version "0.0.12"
"@agile-ts/react@file:.yalc/@agile-ts/react":
- version "0.0.11"
+ version "0.0.12"
"@babel/code-frame@7.8.3":
version "7.8.3"
diff --git a/examples/react/multieditor-ts/README.md b/examples/react/multieditor-ts/README.md
index 1d6d2186..eb14ae46 100644
--- a/examples/react/multieditor-ts/README.md
+++ b/examples/react/multieditor-ts/README.md
@@ -14,18 +14,18 @@ This Example represents the basic features of the `multieditor` package in a **f
#### 1. Run `npm install` at the root of Agile
At first, we have to install some 'global' dependencies of AgileTs.
-#### 2. Run `npm run install-all` at the root of Agile
+#### 2. Run `npm run install:agile` at the root of Agile
Then we install the dependencies of all AgileTs Packages (core, react, api, ..)
-#### 3. Run `npm run dev-publish` at the root of Agile
+#### 3. Run `npm run dev:publish` at the root of Agile
As next step we `publish` all AgileTs Packages to our local `yalc` repository,
to import them later in our examples.
-#### 4. Run `npm run install-agile` in this Project
+#### 4. Run `npm run install:agile` in this Project
To run the example we have to install the dependencies of it, too.
We aren't using `npm install`, because we want to add the just published AgileTs Packages properly.
-#### 5. Run `npm run dev-push` at the root of Agile
+#### 5. Run `npm run dev:push` at the root of Agile
After 'publishing' the AgileTs Packages and installing the dependencies of the example, we can push our changes,
which we might have made for instance in the core package, to yalc by running this command.
All projects having a dependency of the pushed package will receive the changes immediately.
diff --git a/examples/react/multieditor-ts/package.json b/examples/react/multieditor-ts/package.json
index 3977e646..1c8a5e8c 100644
--- a/examples/react/multieditor-ts/package.json
+++ b/examples/react/multieditor-ts/package.json
@@ -26,7 +26,7 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
- "install-agile": "yalc add @agile-ts/core @agile-ts/react @agile-ts/multieditor & yarn install"
+ "install:agile": "yalc add @agile-ts/core @agile-ts/react @agile-ts/multieditor & yarn install"
},
"eslintConfig": {
"extends": [
diff --git a/jest.config.base.js b/jest.config.base.js
index ab45f35b..e87caab1 100644
--- a/jest.config.base.js
+++ b/jest.config.base.js
@@ -1,9 +1,15 @@
module.exports = {
testEnvironment: 'node',
coveragePathIgnorePatterns: ['(tests/.*.mock).(jsx?|tsx?)$'],
- modulePathIgnorePatterns: ['dist'],
+ modulePathIgnorePatterns: ['dist', 'examples', 'node_modules'],
testMatch: ['/packages/**/tests/**/*.test.ts'],
transform: {
'^.+\\.ts?$': 'ts-jest',
},
+ /* https://stackoverflow.com/questions/63904196/esmoduleinterop-flag-set-still-getting-default-import-error */
+ globals: {
+ 'ts-jest': {
+ tsconfig: '/packages/tsconfig.default.json',
+ },
+ },
};
diff --git a/package.json b/package.json
index 8d608773..f7999410 100644
--- a/package.json
+++ b/package.json
@@ -21,12 +21,13 @@
"watch:react": "cd packages/core && yarn run watch",
"watch:multieditor": "cd packages/core && yarn run watch",
"watch:api": "cd packages/core && yarn run watch",
+ "watch:event": "cd packages/event && yarn run watch",
"test": "jest --passWithNoTests",
"test:coverage": "jest --coverage",
- "dev-publish": "lerna run build && lerna run dev-publish",
- "dev-push": "lerna run build && lerna run dev-push",
+ "dev:publish": "lerna run build && lerna run dev:publish",
+ "dev:push": "lerna run build && lerna run dev:push",
"install:packages": "lerna exec yarn install",
- "bump-version": "changeset",
+ "version:bump": "changeset",
"release": "lerna run release && changeset publish",
"prettier": "prettier --config .prettierrc --write \"**/*.{js,ts}\"",
"lint": "eslint --cache \"**/*.{js,jsx,ts,tsx}\"",
@@ -34,7 +35,8 @@
"pack:core": "cd packages/core && yarn run prepare && yarn run preview",
"pack:react": "cd packages/react && yarn run prepare && yarn run preview",
"pack:multieditor": "cd packages/multieditor && yarn run prepare && yarn run preview",
- "pack:api": "cd packages/api && yarn run prepare && yarn run preview"
+ "pack:api": "cd packages/api && yarn run prepare && yarn run preview",
+ "pack:event": "cd packages/event && yarn run prepare && yarn run preview"
},
"repository": {
"type": "git",
diff --git a/packages/api/README.md b/packages/api/README.md
index 4ab9c790..b536f961 100644
--- a/packages/api/README.md
+++ b/packages/api/README.md
@@ -12,7 +12,8 @@
-
+
+
## ⏰ Short Example
```ts
// Let't create our API
@@ -36,6 +37,7 @@ console.log(response);
*/
```
+
## ❓ Why Agile Api
#### 🚅 Straightforward
@@ -44,28 +46,31 @@ Write minimalistic, boilerplate free code that captures your intent.
- Automatic transform for JSON data
- Configurable Timeout
+
#### 🎯 Easy to Use
Learn the powerful and simple tools of Agile Api in a short amount of time.
+
#### 🍃 Lightweight
Agile Api has an unpacked size of [2kB](https://bundlephobia.com/result?p=@agile-ts/api@0.0.6)
and [0 external dependencies](https://www.npmjs.com/package/@agile-ts/api).
+
## ⬇️ Installation
```
npm install @agile-ts/api
```
-_Be aware that this is no standalone package!_
-To use the Agile Api you have to install the [Agile Core](https://www.npmjs.com/package/@agile-ts/core).
-To find out more take a look into the [docs](https://www.agile-ts.org/docs).
-
+The `api` package is an extension of AgileTs and doesn't work without the [`core`](https://agile-ts.org/docs/core) package,
+which functions as the brain of AgileTs and is indispensable.
+Unfortunately, we can't combine each `core` with `api` version.
+Therefore, we have created a table which shows which versions fit together without restrictions.
-## 🔑 Fitting Versions
-| @agile-ts/api | @agile-ts/core | NPM Version |
-| --------------- | ----------------------- | ------------------------ |
-| v0.0.7 | v0.0.1+ | v6+ |
-| v0.0.6 | v0.0.1+ | v6+ |
+| @agile-ts/api | @agile-ts/core | NPM Version |
+| ----------------------| ----------------------- | ------------------------ |
+| v0.0.7+ | v0.0.7+ | v6+ |
+| v0.0.6 | v0.0.3 - v0.0.6 | v6+ |
_Other Versions aren't supported anymore_
+
## 📄 Documentation
-The Agile Api Docs are located [here](https://agile-ts.org/docs/)
+The Agile Api Docs are located [here](https://agile-ts.org/docs/)
\ No newline at end of file
diff --git a/packages/api/package.json b/packages/api/package.json
index a398390c..4e6d0ff9 100644
--- a/packages/api/package.json
+++ b/packages/api/package.json
@@ -17,9 +17,9 @@
"scripts": {
"build": "tsc",
"prepare": "tsc && tsc -p ./tsconfig.production.json",
- "dev-publish": "yalc publish",
- "dev-push": "yalc push",
- "watch": "tsc-watch --onSuccess \"yarn run dev-push\"",
+ "dev:publish": "yalc publish",
+ "dev:push": "yalc push",
+ "watch": "tsc-watch --onSuccess \"yarn run dev:push\"",
"release": "yarn run prepare",
"preview": "npm pack"
},
diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts
index 50879924..acecb4b9 100644
--- a/packages/api/src/index.ts
+++ b/packages/api/src/index.ts
@@ -139,8 +139,8 @@ export default class API {
}/${endpoint}`;
// Warning if fullUrl might be invalid
- if (!isValidUrl(fullUrl))
- console.warn(`Url '${fullUrl}' might be invalid!`);
+ // if (!isValidUrl(fullUrl))
+ // Agile.logger.warn(`Url '${fullUrl}' might be invalid!`);
// Send Request with Timeout
if (this.config.timeout) {
diff --git a/packages/core/package.json b/packages/core/package.json
index 08ad2296..1b7d591a 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -18,9 +18,9 @@
"scripts": {
"build": "tsc",
"prepare": "tsc && tsc -p ./tsconfig.production.json",
- "dev-publish": "yalc publish",
- "dev-push": "yalc push",
- "watch": "tsc-watch --onSuccess \"yarn run dev-push\"",
+ "dev:publish": "yalc publish",
+ "dev:push": "yalc push",
+ "watch": "tsc-watch --onSuccess \"yarn run dev:push\"",
"release": "node ./scripts/prepublish.js && yarn run prepare",
"preview": "npm pack"
},
diff --git a/packages/core/src/agile.ts b/packages/core/src/agile.ts
index 2c08c887..5f424289 100644
--- a/packages/core/src/agile.ts
+++ b/packages/core/src/agile.ts
@@ -7,9 +7,6 @@ import {
CollectionConfig,
DefaultItem,
Computed,
- Event,
- CreateEventConfigInterface,
- DefaultEventPayload,
Integrations,
Observer,
SubController,
@@ -176,20 +173,6 @@ export class Agile {
);
}
- //=========================================================================================================
- // Event
- //=========================================================================================================
- /**
- * @public
- * Event - Class that holds a List of Functions which can be triggered at the same time
- * @param config - Config
- */
- public createEvent(
- config?: CreateEventConfigInterface
- ) {
- return new Event(this, config);
- }
-
//=========================================================================================================
// Integrate
//=========================================================================================================
diff --git a/packages/core/src/collection/group.ts b/packages/core/src/collection/group.ts
index 27ef35eb..d46f11db 100644
--- a/packages/core/src/collection/group.ts
+++ b/packages/core/src/collection/group.ts
@@ -114,7 +114,7 @@ export class Group extends State> {
*/
public remove(
itemKeys: ItemKey | ItemKey[],
- config: GroupRemoveConfig = {}
+ config: GroupRemoveConfigInterface = {}
): this {
const _itemKeys = normalizeArray(itemKeys);
const notExistingItemKeysInCollection: Array = [];
@@ -165,12 +165,15 @@ export class Group extends State> {
* @param itemKeys - ItemKey/s that get added to the Group
* @param config - Config
*/
- public add(itemKeys: ItemKey | ItemKey[], config: GroupAddConfig = {}): this {
+ public add(
+ itemKeys: ItemKey | ItemKey[],
+ config: GroupAddConfigInterface = {}
+ ): this {
const _itemKeys = normalizeArray(itemKeys);
const notExistingItemKeysInCollection: Array = [];
const existingItemKeys: Array = [];
let newGroupValue = copy(this.nextStateValue);
- config = defineConfig(config, {
+ config = defineConfig(config, {
method: 'push',
overwrite: false,
background: false,
@@ -296,7 +299,7 @@ export class Group extends State> {
* @internal
* Rebuilds Output and Items of Group
*/
- public rebuild() {
+ public rebuild(): this {
const notFoundItemKeys: Array = []; // Item Keys that couldn't be found in Collection
const groupItems: Array- > = [];
@@ -325,6 +328,8 @@ export class Group extends State> {
this.items = groupItems;
this._output = groupOutput;
this.notFoundItemKeys = notFoundItemKeys;
+
+ return this;
}
}
@@ -335,7 +340,7 @@ export type GroupKey = string | number;
* @param overwrite - If adding ItemKey overwrites old ItemKey (-> otherwise it gets added to the end of the Group)
* @param background - If adding ItemKey happens in the background (-> not causing any rerender)
*/
-export interface GroupAddConfig {
+export interface GroupAddConfigInterface {
method?: 'unshift' | 'push';
overwrite?: boolean;
background?: boolean;
@@ -344,7 +349,7 @@ export interface GroupAddConfig {
/**
* @param background - If removing ItemKey happens in the background (-> not causing any rerender)
*/
-export interface GroupRemoveConfig {
+export interface GroupRemoveConfigInterface {
background?: boolean;
}
diff --git a/packages/core/src/collection/index.ts b/packages/core/src/collection/index.ts
index fff70ba3..b9031ca5 100644
--- a/packages/core/src/collection/index.ts
+++ b/packages/core/src/collection/index.ts
@@ -12,7 +12,7 @@ import {
normalizeArray,
copy,
CollectionPersistent,
- GroupAddConfig,
+ GroupAddConfigInterface,
ComputedTracker,
generateId,
SideEffectConfigInterface,
@@ -122,7 +122,7 @@ export class Collection {
*/
public Group(
initialItems?: Array,
- config?: GroupConfigInterface
+ config: GroupConfigInterface = {}
): Group {
if (this.isInstantiated) {
const key = config?.key || generateId();
@@ -150,7 +150,7 @@ export class Collection {
*/
public Selector(
initialKey: ItemKey,
- config?: SelectorConfigInterface
+ config: SelectorConfigInterface = {}
): Selector {
if (this.isInstantiated) {
const key = config?.key || generateId();
@@ -305,7 +305,7 @@ export class Collection {
const item = this.getItem(itemKey, { notExisting: true });
const primaryKey = this.config.primaryKey;
config = defineConfig(config, {
- addNewProperties: true,
+ patch: true,
background: false,
});
@@ -326,20 +326,46 @@ export class Collection {
const newItemKey = changes[primaryKey] || oldItemKey;
const updateItemKey = oldItemKey !== newItemKey;
- // Delete primaryKey from 'changes' because if it has changed, it gets properly updated in 'updateItemKey' (below)
- if (changes[primaryKey]) delete changes[primaryKey];
-
// Update ItemKey
if (updateItemKey)
this.updateItemKey(oldItemKey, newItemKey, {
background: config.background,
});
- // Apply changes to Item
- item.patch(changes as any, {
- background: config.background,
- addNewProperties: config.addNewProperties,
- });
+ // Patch changes into Item
+ if (config.patch) {
+ // Delete primaryKey from 'changes' because if it has changed, it gets properly updated in 'updateItemKey' (see above)
+ if (changes[primaryKey]) delete changes[primaryKey];
+
+ let patchConfig: { addNewProperties?: boolean } =
+ typeof config.patch === 'object' ? config.patch : {};
+ patchConfig = defineConfig(patchConfig, {
+ addNewProperties: true,
+ });
+
+ // Apply changes to Item
+ item.patch(changes as any, {
+ background: config.background,
+ addNewProperties: patchConfig.addNewProperties,
+ });
+ }
+
+ // Set changes into Item
+ if (!config.patch) {
+ // To make sure that the primaryKey doesn't differ from the changes object primaryKey
+ if (changes[this.config.primaryKey] !== itemKey) {
+ changes[this.config.primaryKey] = itemKey;
+ Agile.logger.warn(
+ `By overwriting the whole Item don't forget passing the correct primaryKey!`,
+ changes
+ );
+ }
+
+ // Apply changes to Item
+ item.set(changes as any, {
+ background: config.background,
+ });
+ }
return item;
}
@@ -509,6 +535,18 @@ export class Collection {
return selector;
}
+ //=========================================================================================================
+ // Select
+ //=========================================================================================================
+ /**
+ * @public
+ * Creates new Selector that represents an Item of the Collection
+ * @param itemKey - Key of Item which the Selector represents
+ */
+ public select(itemKey: ItemKey): Selector {
+ return this.createSelector(itemKey, itemKey);
+ }
+
//=========================================================================================================
// Has Selector
//=========================================================================================================
@@ -835,7 +873,7 @@ export class Collection {
* @public
* Resets this Collection
*/
- public reset() {
+ public reset(): this {
// Reset Data
this.data = {};
this.size = 0;
@@ -845,6 +883,8 @@ export class Collection {
// Reset Selectors
for (const key in this.selectors) this.getSelector(key)?.reset();
+
+ return this;
}
//=========================================================================================================
@@ -860,8 +900,8 @@ export class Collection {
public put(
itemKeys: ItemKey | Array,
groupKeys: GroupKey | Array,
- config: GroupAddConfig = {}
- ) {
+ config: GroupAddConfigInterface = {}
+ ): this {
const _itemKeys = normalizeArray(itemKeys);
const _groupKeys = normalizeArray(groupKeys);
@@ -869,6 +909,8 @@ export class Collection {
_groupKeys.forEach((groupKey) => {
this.getGroup(groupKey)?.add(_itemKeys, config);
});
+
+ return this;
}
//=========================================================================================================
@@ -970,7 +1012,12 @@ export class Collection {
* Remove Items from Collection
* @param itemKeys - ItemKey/s that get removed
*/
- public remove(itemKeys: ItemKey | Array) {
+ public remove(
+ itemKeys: ItemKey | Array
+ ): {
+ fromGroups: (groups: Array | ItemKey) => Collection;
+ everywhere: () => Collection;
+ } {
return {
fromGroups: (groups: Array | ItemKey) =>
this.removeFromGroups(itemKeys, groups),
@@ -990,7 +1037,7 @@ export class Collection {
public removeFromGroups(
itemKeys: ItemKey | Array,
groupKeys: GroupKey | Array
- ): void {
+ ): this {
const _itemKeys = normalizeArray(itemKeys);
const _groupKeys = normalizeArray(groupKeys);
@@ -1012,6 +1059,8 @@ export class Collection {
)
this.removeItems(itemKey);
});
+
+ return this;
}
//=========================================================================================================
@@ -1022,7 +1071,7 @@ export class Collection {
* Removes Item completely from Collection
* @param itemKeys - ItemKey/s of Item/s
*/
- public removeItems(itemKeys: ItemKey | Array): void {
+ public removeItems(itemKeys: ItemKey | Array): this {
const _itemKeys = normalizeArray(itemKeys);
_itemKeys.forEach((itemKey) => {
@@ -1050,6 +1099,8 @@ export class Collection {
this.size--;
});
+
+ return this;
}
//=========================================================================================================
@@ -1193,11 +1244,11 @@ export interface CollectConfigInterface {
}
/**
- * @param addNewProperties - If properties that doesn't exist in base ItemData get added
+ * @param patch - If Data gets merged into the current Data
* @param background - If updating an Item happens in the background (-> not causing any rerender)
*/
export interface UpdateConfigInterface {
- addNewProperties?: boolean;
+ patch?: boolean | { addNewProperties?: boolean };
background?: boolean;
}
diff --git a/packages/core/src/computed/index.ts b/packages/core/src/computed/index.ts
index 707b761f..f687f948 100644
--- a/packages/core/src/computed/index.ts
+++ b/packages/core/src/computed/index.ts
@@ -3,7 +3,6 @@ import {
Agile,
defineConfig,
Observer,
- Event,
StateConfigInterface,
ComputedTracker,
Group,
@@ -109,13 +108,13 @@ export class Computed extends State<
}
//=========================================================================================================
- // Compute Values
+ // Compute
//=========================================================================================================
/**
* @internal
- * Computes Value and adds missing Dependencies to Computed
+ * Recomputes value and adds missing dependencies to Computed
*/
- public computeValue(): ComputedValueType {
+ public compute(): ComputedValueType {
// Auto track Observers the computeFunction might depend on
ComputedTracker.track();
const computedValue = this.computeFunction();
@@ -183,7 +182,7 @@ export class Computed extends State<
* @param computedDeps - Hard coded dependencies of Computed Function
*/
export interface ComputedConfigInterface extends StateConfigInterface {
- computedDeps?: Array;
+ computedDeps?: Array;
}
/**
diff --git a/packages/core/src/internal.ts b/packages/core/src/internal.ts
index 756f97e8..2be3650a 100644
--- a/packages/core/src/internal.ts
+++ b/packages/core/src/internal.ts
@@ -44,11 +44,6 @@ export * from './collection/item';
export * from './collection/selector';
export * from './collection/collection.persistent';
-// Event
-export * from './event';
-export * from './event/event.job';
-export * from './event/event.observer';
-
// Integrations
export * from './integrations';
export * from './integrations/integration';
diff --git a/packages/core/src/state/index.ts b/packages/core/src/state/index.ts
index 83268e40..55f9bc32 100644
--- a/packages/core/src/state/index.ts
+++ b/packages/core/src/state/index.ts
@@ -15,7 +15,6 @@ import {
PersistentKey,
ComputedTracker,
StateIngestConfigInterface,
- StateRuntimeJobConfigInterface,
} from '../internal';
export class State {
@@ -34,7 +33,8 @@ export class State {
public sideEffects: {
[key: string]: SideEffectInterface>;
} = {}; // SideEffects of State (will be executed in Runtime)
- public computeMethod?: ComputeMethod;
+ public computeValueMethod?: ComputeValueMethod;
+ public computeExistsMethod: ComputeExistsMethod;
public isPersisted = false; // If State can be stored in Agile Storage (-> successfully integrated persistent)
public persistent: StatePersistent | undefined; // Manages storing State Value into Storage
@@ -68,6 +68,9 @@ export class State {
this.previousStateValue = copy(initialValue);
this.nextStateValue = copy(initialValue);
this.isPlaceholder = true;
+ this.computeExistsMethod = (v) => {
+ return v != null;
+ };
// Initial Set
if (!config.isPlaceholder) this.set(initialValue, { overwrite: true });
@@ -476,7 +479,25 @@ export class State {
* Checks if State exists
*/
public get exists(): boolean {
- return !this.isPlaceholder;
+ return !this.isPlaceholder && this.computeExistsMethod(this.value);
+ }
+
+ //=========================================================================================================
+ // Compute Exists
+ //=========================================================================================================
+ /**
+ * @public
+ * Function that computes the exists status of the State
+ * @param method - Computed Function
+ */
+ public computeExists(method: ComputeExistsMethod): this {
+ if (!isFunction(method)) {
+ Agile.logger.error(`A 'computeExistsMethod' has to be a function!`);
+ return this;
+ }
+ this.computeExistsMethod = method;
+
+ return this;
}
//=========================================================================================================
@@ -521,19 +542,23 @@ export class State {
}
//=========================================================================================================
- // Compute
+ // Compute Value
//=========================================================================================================
/**
* @public
* Function that recomputes State Value if it changes
* @param method - Computed Function
*/
- public compute(method: ComputeMethod): this {
+ public computeValue(method: ComputeValueMethod): this {
if (!isFunction(method)) {
- Agile.logger.error('A computeMethod has to be a function!');
+ Agile.logger.error(`A 'computeValueMethod' has to be a function!`);
return this;
}
- this.computeMethod = method;
+ this.computeValueMethod = method;
+
+ // Initial compute
+ this.set(method(this.nextStateValue));
+
return this;
}
@@ -662,7 +687,8 @@ export interface StatePersistentConfigInterface {
}
export type StateWatcherCallback = (value: T, key: string) => void;
-export type ComputeMethod = (value: T) => T;
+export type ComputeValueMethod = (value: T) => T;
+export type ComputeExistsMethod = (value: T) => boolean;
export type SideEffectFunctionType> = (
instance: Instance,
diff --git a/packages/core/src/state/state.observer.ts b/packages/core/src/state/state.observer.ts
index 1c168454..52bb5301 100644
--- a/packages/core/src/state/state.observer.ts
+++ b/packages/core/src/state/state.observer.ts
@@ -47,7 +47,7 @@ export class StateObserver extends Observer {
const state = this.state();
let newStateValue: ValueType;
- if (state instanceof Computed) newStateValue = state.computeValue();
+ if (state instanceof Computed) newStateValue = state.compute();
else newStateValue = state.nextStateValue;
this.ingestValue(newStateValue, config);
@@ -86,8 +86,8 @@ export class StateObserver extends Observer {
}
// Assign next State Value and compute it if necessary
- this.nextStateValue = state.computeMethod
- ? copy(state.computeMethod(newStateValue))
+ this.nextStateValue = state.computeValueMethod
+ ? copy(state.computeValueMethod(newStateValue))
: copy(newStateValue);
// Check if State Value and new/next Value are equals
diff --git a/packages/core/tests/unit/agile.test.ts b/packages/core/tests/unit/agile.test.ts
index 9aa507da..42cb89e0 100644
--- a/packages/core/tests/unit/agile.test.ts
+++ b/packages/core/tests/unit/agile.test.ts
@@ -5,7 +5,6 @@ import {
SubController,
Integrations,
Storage,
- Event,
Computed,
Collection,
Logger,
@@ -20,7 +19,6 @@ jest.mock('../../src/integrations/index');
jest.mock('../../src/storages/storage');
jest.mock('../../src/collection/index');
jest.mock('../../src/computed/index');
-jest.mock('../../src/event/index');
/* Can't mock Logger because I somehow can't overwrite a static get method
jest.mock("../../src/logger/index", () => {
return class {
@@ -247,28 +245,6 @@ describe('Agile Tests', () => {
});
});
- describe('createEvent function tests', () => {
- const EventMock = Event as jest.MockedClass;
-
- beforeEach(() => {
- EventMock.mockClear();
- });
-
- it('should create Event', () => {
- const eventConfig = {
- rerender: true,
- delay: 1000,
- enabled: true,
- key: 'myCoolEvent',
- };
-
- const event = agile.createEvent(eventConfig);
-
- expect(event).toBeInstanceOf(Event);
- expect(EventMock).toHaveBeenCalledWith(agile, eventConfig);
- });
- });
-
describe('integrate function tests', () => {
it('should integrate provided Framework', () => {
const returnedAgile = agile.integrate(testIntegration);
diff --git a/packages/core/tests/unit/collection/collection.persistent.test.ts b/packages/core/tests/unit/collection/collection.persistent.test.ts
index 4a1d74a1..b5710b8f 100644
--- a/packages/core/tests/unit/collection/collection.persistent.test.ts
+++ b/packages/core/tests/unit/collection/collection.persistent.test.ts
@@ -37,6 +37,7 @@ describe('CollectionPersistent Tests', () => {
jest
.spyOn(CollectionPersistent.prototype, 'instantiatePersistent')
.mockImplementationOnce(function () {
+ // @ts-ignore
this.ready = false;
});
@@ -63,6 +64,7 @@ describe('CollectionPersistent Tests', () => {
jest
.spyOn(CollectionPersistent.prototype, 'instantiatePersistent')
.mockImplementationOnce(function () {
+ // @ts-ignore
this.ready = false;
});
@@ -91,6 +93,7 @@ describe('CollectionPersistent Tests', () => {
jest
.spyOn(CollectionPersistent.prototype, 'instantiatePersistent')
.mockImplementationOnce(function () {
+ // @ts-ignore
this.ready = true;
});
@@ -104,6 +107,7 @@ describe('CollectionPersistent Tests', () => {
jest
.spyOn(CollectionPersistent.prototype, 'instantiatePersistent')
.mockImplementationOnce(function () {
+ // @ts-ignore
this.ready = true;
});
@@ -251,19 +255,21 @@ describe('CollectionPersistent Tests', () => {
});
describe('loadPersistedValue function tests', () => {
- let dummyDefaultGroup: Group;
+ let dummyDefaultGroup: Group;
beforeEach(() => {
collectionPersistent.defaultStorageKey = 'test';
dummyDefaultGroup = new Group(dummyCollection, ['1', '2', '3']);
dummyDefaultGroup.persistent = new StatePersistent(dummyDefaultGroup);
- dummyDefaultGroup.persistent.ready = true;
+ if (dummyDefaultGroup.persistent)
+ dummyDefaultGroup.persistent.ready = true;
collectionPersistent.persistValue = jest.fn();
dummyDefaultGroup.persist = jest.fn();
- dummyDefaultGroup.persistent.initialLoading = jest.fn();
+ if (dummyDefaultGroup.persistent)
+ dummyDefaultGroup.persistent.initialLoading = jest.fn();
dummyCollection.collect = jest.fn();
});
@@ -316,7 +322,7 @@ describe('CollectionPersistent Tests', () => {
instantiate: false,
followCollectionPersistKeyPattern: true,
});
- expect(dummyDefaultGroup.persistent.initialLoading).toHaveBeenCalled();
+ expect(dummyDefaultGroup.persistent?.initialLoading).toHaveBeenCalled();
expect(dummyDefaultGroup.isPersisted).toBeTruthy();
expect(dummyCollection.collect).toHaveBeenCalledWith({
@@ -375,7 +381,7 @@ describe('CollectionPersistent Tests', () => {
expect(dummyDefaultGroup.persist).not.toHaveBeenCalled();
expect(
- dummyDefaultGroup.persistent.initialLoading
+ dummyDefaultGroup.persistent?.initialLoading
).not.toHaveBeenCalled();
expect(dummyDefaultGroup.isPersisted).toBeFalsy();
@@ -425,7 +431,7 @@ describe('CollectionPersistent Tests', () => {
instantiate: false,
followCollectionPersistKeyPattern: true,
});
- expect(dummyDefaultGroup.persistent.initialLoading).toHaveBeenCalled();
+ expect(dummyDefaultGroup.persistent?.initialLoading).toHaveBeenCalled();
expect(dummyDefaultGroup.isPersisted).toBeTruthy();
expect(dummyCollection.collect).toHaveBeenCalledWith({
@@ -460,7 +466,7 @@ describe('CollectionPersistent Tests', () => {
expect(dummyDefaultGroup.persist).not.toHaveBeenCalled();
expect(
- dummyDefaultGroup.persistent.initialLoading
+ dummyDefaultGroup.persistent?.initialLoading
).not.toHaveBeenCalled();
expect(dummyDefaultGroup.isPersisted).toBeFalsy();
@@ -513,7 +519,7 @@ describe('CollectionPersistent Tests', () => {
expect(dummyDefaultGroup.persist).not.toHaveBeenCalled();
expect(
- dummyDefaultGroup.persistent.initialLoading
+ dummyDefaultGroup.persistent?.initialLoading
).not.toHaveBeenCalled();
expect(dummyDefaultGroup.isPersisted).toBeFalsy();
@@ -524,11 +530,11 @@ describe('CollectionPersistent Tests', () => {
});
describe('persistValue function tests', () => {
- let dummyDefaultGroup: Group;
+ let dummyDefaultGroup: Group;
beforeEach(() => {
collectionPersistent.storageKeys = ['test1', 'test2'];
- collectionPersistent.isPersisted = undefined;
+ collectionPersistent.isPersisted = undefined as any;
dummyDefaultGroup = new Group(dummyCollection, ['1', '2', '3']);
dummyCollection.data = {
@@ -709,11 +715,11 @@ describe('CollectionPersistent Tests', () => {
});
describe('removePersistedValue function tests', () => {
- let dummyDefaultGroup: Group;
+ let dummyDefaultGroup: Group;
beforeEach(() => {
collectionPersistent.storageKeys = ['test1', 'test2'];
- collectionPersistent.isPersisted = undefined;
+ collectionPersistent.isPersisted = undefined as any;
dummyDefaultGroup = new Group(dummyCollection, ['1', '2', '3']);
dummyDefaultGroup.persistent = new StatePersistent(dummyDefaultGroup);
@@ -722,11 +728,14 @@ describe('CollectionPersistent Tests', () => {
['3']: dummyItem3,
};
- dummyDefaultGroup.persistent.removePersistedValue = jest.fn();
+ if (dummyDefaultGroup.persistent)
+ dummyDefaultGroup.persistent.removePersistedValue = jest.fn();
dummyDefaultGroup.removeSideEffect = jest.fn();
- dummyItem1.persistent.removePersistedValue = jest.fn();
- dummyItem3.persistent.removePersistedValue = jest.fn();
+ if (dummyItem1.persistent)
+ dummyItem1.persistent.removePersistedValue = jest.fn();
+ if (dummyItem3.persistent)
+ dummyItem3.persistent.removePersistedValue = jest.fn();
dummyAgile.storages.remove = jest.fn();
});
@@ -748,14 +757,14 @@ describe('CollectionPersistent Tests', () => {
dummyCollection.config.defaultGroupKey
);
expect(
- dummyDefaultGroup.persistent.removePersistedValue
+ dummyDefaultGroup.persistent?.removePersistedValue
).toHaveBeenCalled();
expect(dummyDefaultGroup.removeSideEffect).toHaveBeenCalledWith(
CollectionPersistent.defaultGroupSideEffectKey
);
- expect(dummyItem1.persistent.removePersistedValue).toHaveBeenCalled();
- expect(dummyItem3.persistent.removePersistedValue).toHaveBeenCalled();
+ expect(dummyItem1.persistent?.removePersistedValue).toHaveBeenCalled();
+ expect(dummyItem3.persistent?.removePersistedValue).toHaveBeenCalled();
expect(collectionPersistent.isPersisted).toBeFalsy();
});
@@ -779,14 +788,14 @@ describe('CollectionPersistent Tests', () => {
dummyCollection.config.defaultGroupKey
);
expect(
- dummyDefaultGroup.persistent.removePersistedValue
+ dummyDefaultGroup.persistent?.removePersistedValue
).toHaveBeenCalled();
expect(dummyDefaultGroup.removeSideEffect).toHaveBeenCalledWith(
CollectionPersistent.defaultGroupSideEffectKey
);
- expect(dummyItem1.persistent.removePersistedValue).toHaveBeenCalled();
- expect(dummyItem3.persistent.removePersistedValue).toHaveBeenCalled();
+ expect(dummyItem1.persistent?.removePersistedValue).toHaveBeenCalled();
+ expect(dummyItem3.persistent?.removePersistedValue).toHaveBeenCalled();
expect(collectionPersistent.isPersisted).toBeFalsy();
});
@@ -803,15 +812,15 @@ describe('CollectionPersistent Tests', () => {
expect(dummyCollection.getGroup).not.toHaveBeenCalled();
expect(
- dummyDefaultGroup.persistent.removePersistedValue
+ dummyDefaultGroup.persistent?.removePersistedValue
).not.toHaveBeenCalled();
expect(dummyDefaultGroup.removeSideEffect).not.toHaveBeenCalled();
expect(
- dummyItem1.persistent.removePersistedValue
+ dummyItem1.persistent?.removePersistedValue
).not.toHaveBeenCalled();
expect(
- dummyItem3.persistent.removePersistedValue
+ dummyItem3.persistent?.removePersistedValue
).not.toHaveBeenCalled();
expect(collectionPersistent.isPersisted).toBeUndefined();
@@ -831,15 +840,15 @@ describe('CollectionPersistent Tests', () => {
dummyCollection.config.defaultGroupKey
);
expect(
- dummyDefaultGroup.persistent.removePersistedValue
+ dummyDefaultGroup.persistent?.removePersistedValue
).not.toHaveBeenCalled();
expect(dummyDefaultGroup.removeSideEffect).not.toHaveBeenCalled();
expect(
- dummyItem1.persistent.removePersistedValue
+ dummyItem1.persistent?.removePersistedValue
).not.toHaveBeenCalled();
expect(
- dummyItem3.persistent.removePersistedValue
+ dummyItem3.persistent?.removePersistedValue
).not.toHaveBeenCalled();
expect(collectionPersistent.isPersisted).toBeUndefined();
@@ -882,7 +891,7 @@ describe('CollectionPersistent Tests', () => {
});
describe('rebuildStorageSideEffects function tests', () => {
- let dummyGroup: Group;
+ let dummyGroup: Group;
beforeEach(() => {
dummyGroup = new Group(dummyCollection);
@@ -899,13 +908,19 @@ describe('CollectionPersistent Tests', () => {
dummyItem3.persist = jest.fn();
dummyItem4WithoutPersistent.persist = jest.fn();
- dummyItem1.persistent.removePersistedValue = jest.fn();
- dummyItem2.persistent.removePersistedValue = jest.fn();
- dummyItem3.persistent.removePersistedValue = jest.fn();
-
- dummyItem1.persistent.persistValue = jest.fn();
- dummyItem2.persistent.persistValue = jest.fn();
- dummyItem3.persistent.persistValue = jest.fn();
+ if (dummyItem1.persistent)
+ dummyItem1.persistent.removePersistedValue = jest.fn();
+ if (dummyItem2.persistent)
+ dummyItem2.persistent.removePersistedValue = jest.fn();
+ if (dummyItem3.persistent)
+ dummyItem3.persistent.removePersistedValue = jest.fn();
+
+ if (dummyItem1.persistent)
+ dummyItem1.persistent.persistValue = jest.fn();
+ if (dummyItem2.persistent)
+ dummyItem2.persistent.persistValue = jest.fn();
+ if (dummyItem3.persistent)
+ dummyItem3.persistent.persistValue = jest.fn();
});
it('should return if no Item got added or removed', () => {
@@ -920,18 +935,18 @@ describe('CollectionPersistent Tests', () => {
expect(dummyItem4WithoutPersistent.persist).not.toHaveBeenCalled();
expect(
- dummyItem1.persistent.removePersistedValue
+ dummyItem1.persistent?.removePersistedValue
).not.toHaveBeenCalled();
expect(
- dummyItem2.persistent.removePersistedValue
+ dummyItem2.persistent?.removePersistedValue
).not.toHaveBeenCalled();
expect(
- dummyItem3.persistent.removePersistedValue
+ dummyItem3.persistent?.removePersistedValue
).not.toHaveBeenCalled();
- expect(dummyItem1.persistent.persistValue).not.toHaveBeenCalled();
- expect(dummyItem2.persistent.persistValue).not.toHaveBeenCalled();
- expect(dummyItem3.persistent.persistValue).not.toHaveBeenCalled();
+ expect(dummyItem1.persistent?.persistValue).not.toHaveBeenCalled();
+ expect(dummyItem2.persistent?.persistValue).not.toHaveBeenCalled();
+ expect(dummyItem3.persistent?.persistValue).not.toHaveBeenCalled();
});
it('should call removePersistedValue on Items that got removed from Group', () => {
@@ -945,19 +960,23 @@ describe('CollectionPersistent Tests', () => {
expect(dummyItem3.persist).not.toHaveBeenCalled();
expect(dummyItem4WithoutPersistent.persist).not.toHaveBeenCalled();
- expect(dummyItem1.persistent.removePersistedValue).toHaveBeenCalledWith(
+ expect(
+ dummyItem1.persistent?.removePersistedValue
+ ).toHaveBeenCalledWith(
CollectionPersistent.getItemStorageKey('1', collectionPersistent._key)
);
expect(
- dummyItem2.persistent.removePersistedValue
+ dummyItem2.persistent?.removePersistedValue
).not.toHaveBeenCalled();
- expect(dummyItem3.persistent.removePersistedValue).toHaveBeenCalledWith(
+ expect(
+ dummyItem3.persistent?.removePersistedValue
+ ).toHaveBeenCalledWith(
CollectionPersistent.getItemStorageKey('3', collectionPersistent._key)
);
- expect(dummyItem1.persistent.persistValue).not.toHaveBeenCalled();
- expect(dummyItem2.persistent.persistValue).not.toHaveBeenCalled();
- expect(dummyItem3.persistent.persistValue).not.toHaveBeenCalled();
+ expect(dummyItem1.persistent?.persistValue).not.toHaveBeenCalled();
+ expect(dummyItem2.persistent?.persistValue).not.toHaveBeenCalled();
+ expect(dummyItem3.persistent?.persistValue).not.toHaveBeenCalled();
});
it('should call persistValue on Items that have a persistent and got added to Group', () => {
@@ -972,20 +991,20 @@ describe('CollectionPersistent Tests', () => {
expect(dummyItem4WithoutPersistent.persist).not.toHaveBeenCalled();
expect(
- dummyItem1.persistent.removePersistedValue
+ dummyItem1.persistent?.removePersistedValue
).not.toHaveBeenCalled();
expect(
- dummyItem2.persistent.removePersistedValue
+ dummyItem2.persistent?.removePersistedValue
).not.toHaveBeenCalled();
expect(
- dummyItem3.persistent.removePersistedValue
+ dummyItem3.persistent?.removePersistedValue
).not.toHaveBeenCalled();
- expect(dummyItem1.persistent.persistValue).not.toHaveBeenCalled();
- expect(dummyItem2.persistent.persistValue).toHaveBeenCalledWith(
+ expect(dummyItem1.persistent?.persistValue).not.toHaveBeenCalled();
+ expect(dummyItem2.persistent?.persistValue).toHaveBeenCalledWith(
CollectionPersistent.getItemStorageKey('2', collectionPersistent._key)
);
- expect(dummyItem3.persistent.persistValue).toHaveBeenCalledWith(
+ expect(dummyItem3.persistent?.persistValue).toHaveBeenCalledWith(
CollectionPersistent.getItemStorageKey('3', collectionPersistent._key)
);
});
@@ -1004,18 +1023,18 @@ describe('CollectionPersistent Tests', () => {
);
expect(
- dummyItem1.persistent.removePersistedValue
+ dummyItem1.persistent?.removePersistedValue
).not.toHaveBeenCalled();
expect(
- dummyItem2.persistent.removePersistedValue
+ dummyItem2.persistent?.removePersistedValue
).not.toHaveBeenCalled();
expect(
- dummyItem3.persistent.removePersistedValue
+ dummyItem3.persistent?.removePersistedValue
).not.toHaveBeenCalled();
- expect(dummyItem1.persistent.persistValue).not.toHaveBeenCalled();
- expect(dummyItem2.persistent.persistValue).not.toHaveBeenCalled();
- expect(dummyItem3.persistent.persistValue).not.toHaveBeenCalled();
+ expect(dummyItem1.persistent?.persistValue).not.toHaveBeenCalled();
+ expect(dummyItem2.persistent?.persistValue).not.toHaveBeenCalled();
+ expect(dummyItem3.persistent?.persistValue).not.toHaveBeenCalled();
});
});
diff --git a/packages/core/tests/unit/collection/collection.test.ts b/packages/core/tests/unit/collection/collection.test.ts
index 22cefdfc..a1044b07 100644
--- a/packages/core/tests/unit/collection/collection.test.ts
+++ b/packages/core/tests/unit/collection/collection.test.ts
@@ -67,7 +67,9 @@ describe('Collection Tests', () => {
jest
.spyOn(Collection.prototype, 'initGroups')
.mockReturnValueOnce(undefined);
- jest.spyOn(Collection.prototype, 'collect').mockReturnValueOnce(undefined);
+ jest
+ .spyOn(Collection.prototype, 'collect')
+ .mockReturnValueOnce(undefined as any);
const collection = new Collection(dummyAgile, {
defaultGroupKey: 'general',
@@ -111,7 +113,9 @@ describe('Collection Tests', () => {
jest
.spyOn(Collection.prototype, 'initGroups')
.mockReturnValueOnce(undefined);
- jest.spyOn(Collection.prototype, 'collect').mockReturnValueOnce(undefined);
+ jest
+ .spyOn(Collection.prototype, 'collect')
+ .mockReturnValueOnce(undefined as any);
const collection = new Collection(
dummyAgile,
@@ -183,30 +187,30 @@ describe('Collection Tests', () => {
});
it('should update existing Key in all instances', () => {
- collection.persistent._key = 'collectionKey';
+ if (collection.persistent) collection.persistent._key = 'collectionKey';
collection.setKey('newKey');
expect(collection._key).toBe('newKey');
- expect(collection.persistent.setKey).toHaveBeenCalledWith('newKey');
+ expect(collection.persistent?.setKey).toHaveBeenCalledWith('newKey');
});
it("should update existing Key in all instances except persistent if the CollectionKey and PersistKey aren't equal", () => {
- collection.persistent._key = 'randomKey';
+ if (collection.persistent) collection.persistent._key = 'randomKey';
collection.setKey('newKey');
expect(collection._key).toBe('newKey');
- expect(collection.persistent.setKey).not.toHaveBeenCalled();
+ expect(collection.persistent?.setKey).not.toHaveBeenCalled();
});
it('should update existing Key in all instances except persistent if new CollectionKey is undefined', () => {
- collection.persistent._key = 'collectionKey';
+ if (collection.persistent) collection.persistent._key = 'collectionKey';
collection.setKey(undefined);
expect(collection._key).toBeUndefined();
- expect(collection.persistent.setKey).not.toHaveBeenCalled();
+ expect(collection.persistent?.setKey).not.toHaveBeenCalled();
});
});
@@ -448,9 +452,9 @@ describe('Collection Tests', () => {
});
describe('collect function tests', () => {
- let dummyGroup1: Group;
- let dummyGroup2: Group;
- let defaultGroup: Group;
+ let dummyGroup1: Group;
+ let dummyGroup2: Group;
+ let defaultGroup: Group;
beforeEach(() => {
dummyGroup1 = new Group(collection);
@@ -623,6 +627,7 @@ describe('Collection Tests', () => {
notExistingGroup.add = jest.fn();
collection.setData = jest.fn(() => true);
collection.createGroup = jest.fn(function (groupKey) {
+ //@ts-ignore
this.groups[groupKey] = notExistingGroup;
return notExistingGroup as any;
});
@@ -707,14 +712,16 @@ describe('Collection Tests', () => {
};
dummyItem.patch = jest.fn();
+ dummyItem.set = jest.fn();
collection.updateItemKey = jest.fn();
});
- it('should update existing Item with valid changes Object (default config)', () => {
+ it('should update existing Item by patching valid changes Object (default config)', () => {
const response = collection.update('dummyItem', { name: 'hans' });
expect(response).toBe(dummyItem);
expect(console.error).not.toHaveBeenCalled();
+ expect(console.warn).not.toHaveBeenCalled();
expect(dummyItem.patch).toHaveBeenCalledWith(
{
name: 'hans',
@@ -724,21 +731,22 @@ describe('Collection Tests', () => {
addNewProperties: true,
}
);
+ expect(dummyItem.set).not.toHaveBeenCalled();
expect(collection.updateItemKey).not.toHaveBeenCalled();
});
- it('should update existing Item with valid changes Object (specific config)', () => {
+ it('should update existing Item by patching valid changes Object (specific config)', () => {
const response = collection.update(
'dummyItem',
{ name: 'hans' },
{
- addNewProperties: true,
background: true,
}
);
expect(response).toBe(dummyItem);
expect(console.error).not.toHaveBeenCalled();
+ expect(console.warn).not.toHaveBeenCalled();
expect(dummyItem.patch).toHaveBeenCalledWith(
{
name: 'hans',
@@ -748,16 +756,18 @@ describe('Collection Tests', () => {
addNewProperties: true,
}
);
+ expect(dummyItem.set).not.toHaveBeenCalled();
expect(collection.updateItemKey).not.toHaveBeenCalled();
});
- it('should update existing placeholder Item with valid changes Object (default config)', () => {
+ it('should update existing placeholder Item by patching valid changes Object (default config)', () => {
dummyItem.isPlaceholder = true;
const response = collection.update('dummyItem', { name: 'hans' });
expect(response).toBe(dummyItem);
expect(console.error).not.toHaveBeenCalled();
+ expect(console.warn).not.toHaveBeenCalled();
expect(dummyItem.patch).toHaveBeenCalledWith(
{
name: 'hans',
@@ -767,6 +777,69 @@ describe('Collection Tests', () => {
addNewProperties: true,
}
);
+ expect(dummyItem.set).not.toHaveBeenCalled();
+ expect(collection.updateItemKey).not.toHaveBeenCalled();
+ });
+
+ it('should update existing Item by setting valid changes Object (default config)', () => {
+ const response = collection.update(
+ 'dummyItem',
+ { id: 'dummyItem', name: 'hans' },
+ { patch: false }
+ );
+
+ expect(response).toBe(dummyItem);
+ expect(console.error).not.toHaveBeenCalled();
+ expect(console.warn).not.toHaveBeenCalled();
+ expect(dummyItem.patch).not.toHaveBeenCalled();
+ expect(dummyItem.set).toHaveBeenCalledWith(
+ { id: 'dummyItem', name: 'hans' },
+ { background: false }
+ );
+ expect(collection.updateItemKey).not.toHaveBeenCalled();
+ });
+
+ it('should update existing Item by setting valid changes Object (specific config)', () => {
+ const response = collection.update(
+ 'dummyItem',
+ { id: 'dummyItem', name: 'hans' },
+ {
+ patch: false,
+ background: true,
+ }
+ );
+
+ expect(response).toBe(dummyItem);
+ expect(console.error).not.toHaveBeenCalled();
+ expect(console.warn).not.toHaveBeenCalled();
+ expect(dummyItem.patch).not.toHaveBeenCalled();
+ expect(dummyItem.set).toHaveBeenCalledWith(
+ { id: 'dummyItem', name: 'hans' },
+ { background: true }
+ );
+ expect(collection.updateItemKey).not.toHaveBeenCalled();
+ });
+
+ it('should update existing Item by setting valid changes Object without primaryKey and should print warning (default config)', () => {
+ const response = collection.update(
+ 'dummyItem',
+ { name: 'hans' },
+ { patch: false }
+ );
+
+ expect(response).toBe(dummyItem);
+ expect(console.error).not.toHaveBeenCalled();
+ expect(
+ console.warn
+ ).toHaveBeenCalledWith(
+ "Agile Warn: By overwriting the whole Item don't forget passing the correct primaryKey!",
+ { id: 'dummyItem', name: 'hans' }
+ );
+ expect(dummyItem.patch).not.toHaveBeenCalled();
+ expect(dummyItem.set).toHaveBeenCalledWith(
+ { id: 'dummyItem', name: 'hans' },
+ { background: false }
+ );
expect(collection.updateItemKey).not.toHaveBeenCalled();
});
@@ -777,7 +850,9 @@ describe('Collection Tests', () => {
expect(console.error).toHaveBeenCalledWith(
`Agile Error: Item with key/name 'notExisting' doesn't exist in Collection '${collection._key}'!`
);
+ expect(console.warn).not.toHaveBeenCalled();
expect(dummyItem.patch).not.toHaveBeenCalled();
+ expect(dummyItem.set).not.toHaveBeenCalled();
expect(collection.updateItemKey).not.toHaveBeenCalled();
});
@@ -791,7 +866,9 @@ describe('Collection Tests', () => {
expect(console.error).toHaveBeenCalledWith(
`Agile Error: You have to pass an valid Changes Object to update 'dummyItem' in '${collection._key}'!`
);
+ expect(console.warn).not.toHaveBeenCalled();
expect(dummyItem.patch).not.toHaveBeenCalled();
+ expect(dummyItem.set).not.toHaveBeenCalled();
expect(collection.updateItemKey).not.toHaveBeenCalled();
});
@@ -803,6 +880,7 @@ describe('Collection Tests', () => {
expect(response).toBe(dummyItem);
expect(console.error).not.toHaveBeenCalled();
+ expect(console.warn).not.toHaveBeenCalled();
expect(dummyItem.patch).toHaveBeenCalledWith(
{
name: 'hans',
@@ -812,6 +890,7 @@ describe('Collection Tests', () => {
addNewProperties: true,
}
);
+ expect(dummyItem.set).not.toHaveBeenCalled();
expect(collection.updateItemKey).toHaveBeenCalledWith(
'dummyItem',
'newDummyItemKey',
@@ -823,7 +902,7 @@ describe('Collection Tests', () => {
});
describe('createGroup function tests', () => {
- let dummyGroup: Group;
+ let dummyGroup: Group;
let dummyItem: Item;
beforeEach(() => {
@@ -877,7 +956,7 @@ describe('Collection Tests', () => {
});
describe('hasGroup function tests', () => {
- let dummyGroup: Group;
+ let dummyGroup: Group;
beforeEach(() => {
dummyGroup = new Group(collection, []);
@@ -916,7 +995,7 @@ describe('Collection Tests', () => {
});
describe('getGroup function tests', () => {
- let dummyGroup: Group;
+ let dummyGroup: Group;
beforeEach(() => {
dummyGroup = new Group(collection, [], { key: 'dummyGroup' });
@@ -967,7 +1046,7 @@ describe('Collection Tests', () => {
});
describe('getGroupWithReference function tests', () => {
- let dummyGroup: Group;
+ let dummyGroup: Group;
beforeEach(() => {
dummyGroup = new Group(collection, [], { key: 'dummyGroup' });
@@ -999,7 +1078,7 @@ describe('Collection Tests', () => {
});
describe('removeGroup function tests', () => {
- let dummyGroup: Group;
+ let dummyGroup: Group;
beforeEach(() => {
dummyGroup = new Group(collection, [], { key: 'dummyGroup' });
@@ -1025,7 +1104,7 @@ describe('Collection Tests', () => {
});
describe('createSelector function tests', () => {
- let dummySelector: Selector;
+ let dummySelector: Selector;
let dummyItem: Item;
beforeEach(() => {
@@ -1087,7 +1166,7 @@ describe('Collection Tests', () => {
});
describe('hasSelector function tests', () => {
- let dummySelector: Selector;
+ let dummySelector: Selector;
beforeEach(() => {
dummySelector = new Selector(collection, 'unknown');
@@ -1126,7 +1205,7 @@ describe('Collection Tests', () => {
});
describe('getSelector function tests', () => {
- let dummySelector: Selector;
+ let dummySelector: Selector;
beforeEach(() => {
dummySelector = new Selector(collection, 'dummyItem', {
@@ -1179,7 +1258,7 @@ describe('Collection Tests', () => {
});
describe('getSelectorWithReference function tests', () => {
- let dummySelector: Selector;
+ let dummySelector: Selector;
beforeEach(() => {
dummySelector = new Selector(collection, 'dummyItem', {
@@ -1215,7 +1294,7 @@ describe('Collection Tests', () => {
});
describe('removeSelector function tests', () => {
- let dummySelector: Selector;
+ let dummySelector: Selector;
beforeEach(() => {
dummySelector = new Selector(collection, 'dummyItem', {
@@ -1630,8 +1709,8 @@ describe('Collection Tests', () => {
});
describe('reset function tests', () => {
- let dummyGroup: Group;
- let dummySelector: Selector;
+ let dummyGroup: Group;
+ let dummySelector: Selector;
let dummyItem: Item;
beforeEach(() => {
@@ -1665,8 +1744,8 @@ describe('Collection Tests', () => {
});
describe('put function tests', () => {
- let dummyGroup1: Group;
- let dummyGroup2: Group;
+ let dummyGroup1: Group;
+ let dummyGroup2: Group;
beforeEach(() => {
dummyGroup1 = new Group(collection, [], { key: 'dummyGroup1' });
@@ -1712,11 +1791,11 @@ describe('Collection Tests', () => {
});
describe('updateItemKey function tests', () => {
- let dummySelector1: Selector;
- let dummySelector2: Selector;
- let dummySelector3: Selector;
- let dummyGroup1: Group;
- let dummyGroup2: Group;
+ let dummySelector1: Selector;
+ let dummySelector2: Selector;
+ let dummySelector3: Selector;
+ let dummyGroup1: Group;
+ let dummyGroup2: Group;
let dummyItem1: Item;
let dummyItem2: Item;
@@ -1778,13 +1857,13 @@ describe('Collection Tests', () => {
background: false,
});
expect(dummyItem2.setKey).not.toHaveBeenCalled();
- expect(dummyItem1.persistent.setKey).toHaveBeenCalledWith(
+ expect(dummyItem1.persistent?.setKey).toHaveBeenCalledWith(
CollectionPersistent.getItemStorageKey(
'newDummyItem',
collection._key
)
);
- expect(dummyItem2.persistent.setKey).not.toHaveBeenCalled();
+ expect(dummyItem2.persistent?.setKey).not.toHaveBeenCalled();
expect(dummyGroup1.replace).toHaveBeenCalledWith(
'dummyItem1',
@@ -1819,7 +1898,7 @@ describe('Collection Tests', () => {
expect(dummyItem1.setKey).toHaveBeenCalledWith('newDummyItem', {
background: true,
});
- expect(dummyItem1.persistent.setKey).toHaveBeenCalledWith(
+ expect(dummyItem1.persistent?.setKey).toHaveBeenCalledWith(
CollectionPersistent.getItemStorageKey(
'newDummyItem',
collection._key
@@ -1854,7 +1933,7 @@ describe('Collection Tests', () => {
expect(dummyItem1.setKey).toHaveBeenCalledWith('newDummyItem', {
background: false,
});
- expect(dummyItem1.persistent.setKey).toHaveBeenCalledWith(
+ expect(dummyItem1.persistent?.setKey).toHaveBeenCalledWith(
CollectionPersistent.getItemStorageKey(
'newDummyItem',
collection._key
@@ -1904,9 +1983,9 @@ describe('Collection Tests', () => {
});
describe('getGroupKeysThatHaveItemKey function tests', () => {
- let dummyGroup1: Group;
- let dummyGroup2: Group;
- let dummyGroup3: Group;
+ let dummyGroup1: Group;
+ let dummyGroup2: Group;
+ let dummyGroup3: Group;
beforeEach(() => {
dummyGroup1 = new Group(
@@ -1972,9 +2051,9 @@ describe('Collection Tests', () => {
});
describe('removeFromGroups function tests', () => {
- let dummyGroup1: Group;
- let dummyGroup2: Group;
- let dummyGroup3: Group;
+ let dummyGroup1: Group;
+ let dummyGroup2: Group;
+ let dummyGroup3: Group;
beforeEach(() => {
dummyGroup1 = new Group(
@@ -2042,10 +2121,10 @@ describe('Collection Tests', () => {
});
describe('removeItems function test', () => {
- let dummySelector1: Selector;
- let dummySelector2: Selector;
- let dummyGroup1: Group;
- let dummyGroup2: Group;
+ let dummySelector1: Selector;
+ let dummySelector2: Selector;
+ let dummyGroup1: Group;
+ let dummyGroup2: Group;
let dummyItem1: Item;
let dummyItem2: Item;
@@ -2099,9 +2178,9 @@ describe('Collection Tests', () => {
expect(collection.data).toHaveProperty('dummyItem2');
expect(collection.size).toBe(1);
- expect(dummyItem1.persistent.removePersistedValue).toHaveBeenCalled();
+ expect(dummyItem1.persistent?.removePersistedValue).toHaveBeenCalled();
expect(
- dummyItem2.persistent.removePersistedValue
+ dummyItem2.persistent?.removePersistedValue
).not.toHaveBeenCalled();
expect(dummyGroup1.remove).toHaveBeenCalledWith('dummyItem1');
@@ -2120,8 +2199,8 @@ describe('Collection Tests', () => {
expect(collection.data).not.toHaveProperty('dummyItem2');
expect(collection.size).toBe(0);
- expect(dummyItem1.persistent.removePersistedValue).toHaveBeenCalled();
- expect(dummyItem2.persistent.removePersistedValue).toHaveBeenCalled();
+ expect(dummyItem1.persistent?.removePersistedValue).toHaveBeenCalled();
+ expect(dummyItem2.persistent?.removePersistedValue).toHaveBeenCalled();
expect(dummyGroup1.remove).toHaveBeenCalledWith('dummyItem1');
expect(dummyGroup1.remove).toHaveBeenCalledWith('dummyItem2');
@@ -2273,8 +2352,8 @@ describe('Collection Tests', () => {
});
describe('rebuildGroupsThatIncludeItemKey function tests', () => {
- let dummyGroup1: Group;
- let dummyGroup2: Group;
+ let dummyGroup1: Group;
+ let dummyGroup2: Group;
beforeEach(() => {
dummyGroup1 = new Group(collection, ['dummyItem1', 'dummyItem2'], {
diff --git a/packages/core/tests/unit/collection/group.test.ts b/packages/core/tests/unit/collection/group.test.ts
index dff4258b..75f95a69 100644
--- a/packages/core/tests/unit/collection/group.test.ts
+++ b/packages/core/tests/unit/collection/group.test.ts
@@ -34,8 +34,12 @@ describe('Group Tests', () => {
it('should create Group with no initialItems (default config)', () => {
// Overwrite methods once to not call it
- jest.spyOn(Group.prototype, 'rebuild').mockReturnValueOnce(undefined);
- jest.spyOn(Group.prototype, 'addSideEffect').mockReturnValueOnce(undefined);
+ jest
+ .spyOn(Group.prototype, 'rebuild')
+ .mockReturnValueOnce(undefined as any);
+ jest
+ .spyOn(Group.prototype, 'addSideEffect')
+ .mockReturnValueOnce(undefined as any);
const group = new Group(dummyCollection);
@@ -56,7 +60,8 @@ describe('Group Tests', () => {
expect(group.observer.dependents.size).toBe(0);
expect(group.observer._key).toBeUndefined();
expect(group.sideEffects).toStrictEqual({});
- expect(group.computeMethod).toBeUndefined();
+ expect(group.computeValueMethod).toBeUndefined();
+ expect(group.computeExistsMethod).toBeInstanceOf(Function);
expect(group.isPersisted).toBeFalsy();
expect(group.persistent).toBeUndefined();
expect(group.watchers).toStrictEqual({});
@@ -64,8 +69,12 @@ describe('Group Tests', () => {
it('should create Group with no initialItems (specific config)', () => {
// Overwrite methods once to not call it
- jest.spyOn(Group.prototype, 'rebuild').mockReturnValueOnce(undefined);
- jest.spyOn(Group.prototype, 'addSideEffect').mockReturnValueOnce(undefined);
+ jest
+ .spyOn(Group.prototype, 'rebuild')
+ .mockReturnValueOnce(undefined as any);
+ jest
+ .spyOn(Group.prototype, 'addSideEffect')
+ .mockReturnValueOnce(undefined as any);
const group = new Group(dummyCollection, [], {
key: 'dummyKey',
@@ -89,7 +98,8 @@ describe('Group Tests', () => {
expect(group.observer.dependents.size).toBe(0);
expect(group.observer._key).toBe('dummyKey');
expect(group.sideEffects).toStrictEqual({});
- expect(group.computeMethod).toBeUndefined();
+ expect(group.computeValueMethod).toBeUndefined();
+ expect(group.computeExistsMethod).toBeInstanceOf(Function);
expect(group.isPersisted).toBeFalsy();
expect(group.persistent).toBeUndefined();
expect(group.watchers).toStrictEqual({});
@@ -97,8 +107,12 @@ describe('Group Tests', () => {
it('should create Group with initialItems (default config)', () => {
// Overwrite methods once to not call it
- jest.spyOn(Group.prototype, 'rebuild').mockReturnValueOnce(undefined);
- jest.spyOn(Group.prototype, 'addSideEffect').mockReturnValueOnce(undefined);
+ jest
+ .spyOn(Group.prototype, 'rebuild')
+ .mockReturnValueOnce(undefined as any);
+ jest
+ .spyOn(Group.prototype, 'addSideEffect')
+ .mockReturnValueOnce(undefined as any);
const group = new Group(dummyCollection, ['test1', 'test2', 'test3']);
@@ -119,7 +133,8 @@ describe('Group Tests', () => {
expect(group.observer.dependents.size).toBe(0);
expect(group.observer._key).toBeUndefined();
expect(group.sideEffects).toStrictEqual({});
- expect(group.computeMethod).toBeUndefined();
+ expect(group.computeValueMethod).toBeUndefined();
+ expect(group.computeExistsMethod).toBeInstanceOf(Function);
expect(group.isPersisted).toBeFalsy();
expect(group.persistent).toBeUndefined();
expect(group.watchers).toStrictEqual({});
@@ -137,8 +152,8 @@ describe('Group Tests', () => {
});
dummyCollection.collect({ id: 'dummyItem1Key', name: 'coolName' });
dummyCollection.collect({ id: 'dummyItem2Key', name: 'coolName' });
- dummyItem1 = dummyCollection.getItem('dummyItem1Key');
- dummyItem2 = dummyCollection.getItem('dummyItem2Key');
+ dummyItem1 = dummyCollection.getItem('dummyItem1Key') as any;
+ dummyItem2 = dummyCollection.getItem('dummyItem2Key') as any;
dummyItem3 = new Item(dummyCollection, {
id: 'dummyItem3Key',
name: 'coolName',
diff --git a/packages/core/tests/unit/collection/item.test.ts b/packages/core/tests/unit/collection/item.test.ts
index 5e82d9f2..1b99a39c 100644
--- a/packages/core/tests/unit/collection/item.test.ts
+++ b/packages/core/tests/unit/collection/item.test.ts
@@ -41,7 +41,8 @@ describe('Item Tests', () => {
dummyData[dummyCollection.config.primaryKey]
);
expect(item.sideEffects).toStrictEqual({});
- expect(item.computeMethod).toBeUndefined();
+ expect(item.computeValueMethod).toBeUndefined();
+ expect(item.computeExistsMethod).toBeInstanceOf(Function);
expect(item.isPersisted).toBeFalsy();
expect(item.persistent).toBeUndefined();
expect(item.watchers).toStrictEqual({});
@@ -78,7 +79,8 @@ describe('Item Tests', () => {
dummyData[dummyCollection.config.primaryKey]
);
expect(item.sideEffects).toStrictEqual({});
- expect(item.computeMethod).toBeUndefined();
+ expect(item.computeValueMethod).toBeUndefined();
+ expect(item.computeExistsMethod).toBeInstanceOf(Function);
expect(item.isPersisted).toBeFalsy();
expect(item.persistent).toBeUndefined();
expect(item.watchers).toStrictEqual({});
diff --git a/packages/core/tests/unit/collection/selector.test.ts b/packages/core/tests/unit/collection/selector.test.ts
index 27673b59..78fa2c44 100644
--- a/packages/core/tests/unit/collection/selector.test.ts
+++ b/packages/core/tests/unit/collection/selector.test.ts
@@ -20,7 +20,9 @@ describe('Selector Tests', () => {
it('should create Selector and call initial select (default config)', () => {
// Overwrite select once to not call it
- jest.spyOn(Selector.prototype, 'select').mockReturnValueOnce(undefined);
+ jest
+ .spyOn(Selector.prototype, 'select')
+ .mockReturnValueOnce(undefined as any);
const selector = new Selector(dummyCollection, 'dummyItemKey');
@@ -43,7 +45,8 @@ describe('Selector Tests', () => {
expect(selector.observer.dependents.size).toBe(0);
expect(selector.observer._key).toBeUndefined();
expect(selector.sideEffects).toStrictEqual({});
- expect(selector.computeMethod).toBeUndefined();
+ expect(selector.computeValueMethod).toBeUndefined();
+ expect(selector.computeExistsMethod).toBeInstanceOf(Function);
expect(selector.isPersisted).toBeFalsy();
expect(selector.persistent).toBeUndefined();
expect(selector.watchers).toStrictEqual({});
@@ -51,7 +54,9 @@ describe('Selector Tests', () => {
it('should create Selector and call initial select (specific config)', () => {
// Overwrite select once to not call it
- jest.spyOn(Selector.prototype, 'select').mockReturnValueOnce(undefined);
+ jest
+ .spyOn(Selector.prototype, 'select')
+ .mockReturnValueOnce(undefined as any);
const selector = new Selector(dummyCollection, 'dummyItemKey', {
key: 'dummyKey',
@@ -76,7 +81,8 @@ describe('Selector Tests', () => {
expect(selector.observer.dependents.size).toBe(0);
expect(selector.observer._key).toBe('dummyKey');
expect(selector.sideEffects).toStrictEqual({});
- expect(selector.computeMethod).toBeUndefined();
+ expect(selector.computeValueMethod).toBeUndefined();
+ expect(selector.computeExistsMethod).toBeInstanceOf(Function);
expect(selector.isPersisted).toBeFalsy();
expect(selector.persistent).toBeUndefined();
expect(selector.watchers).toStrictEqual({});
@@ -84,7 +90,9 @@ describe('Selector Tests', () => {
it("should create Selector and shouldn't call initial select (config.isPlaceholder = true)", () => {
// Overwrite select once to not call it
- jest.spyOn(Selector.prototype, 'select').mockReturnValueOnce(undefined);
+ jest
+ .spyOn(Selector.prototype, 'select')
+ .mockReturnValueOnce(undefined as any);
const selector = new Selector(dummyCollection, 'dummyItemKey', {
isPlaceholder: true,
@@ -107,7 +115,8 @@ describe('Selector Tests', () => {
expect(selector.observer.dependents.size).toBe(0);
expect(selector.observer._key).toBeUndefined();
expect(selector.sideEffects).toStrictEqual({});
- expect(selector.computeMethod).toBeUndefined();
+ expect(selector.computeValueMethod).toBeUndefined();
+ expect(selector.computeExistsMethod).toBeInstanceOf(Function);
expect(selector.isPersisted).toBeFalsy();
expect(selector.persistent).toBeUndefined();
expect(selector.watchers).toStrictEqual({});
@@ -532,25 +541,25 @@ describe('Selector Tests', () => {
});
it('should return true if Selector has selected ItemKey and Item isSelected', () => {
- selector.item.isSelected = true;
+ if (selector.item) selector.item.isSelected = true;
expect(selector.hasSelected('dummyItemKey')).toBeTruthy();
});
it("should return false if Selector hasn't selected ItemKey and Item isSelected", () => {
- selector.item.isSelected = true;
+ if (selector.item) selector.item.isSelected = true;
expect(selector.hasSelected('notSelectedItemKey')).toBeFalsy();
});
it("should return false if Selector has selected ItemKey and Item isn't isSelected", () => {
- selector.item.isSelected = false;
+ if (selector.item) selector.item.isSelected = false;
expect(selector.hasSelected('dummyItemKey')).toBeFalsy();
});
it("should return false if Selector hasn't selected ItemKey and Item isn't isSelected", () => {
- selector.item.isSelected = false;
+ if (selector.item) selector.item.isSelected = false;
expect(selector.hasSelected('notSelectedItemKey')).toBeFalsy();
});
diff --git a/packages/core/tests/unit/computed/computed.test.ts b/packages/core/tests/unit/computed/computed.test.ts
index e6cee1f8..71a822fa 100644
--- a/packages/core/tests/unit/computed/computed.test.ts
+++ b/packages/core/tests/unit/computed/computed.test.ts
@@ -37,7 +37,8 @@ describe('Computed Tests', () => {
expect(computed.observer.dependents.size).toBe(0);
expect(computed.observer._key).toBeUndefined();
expect(computed.sideEffects).toStrictEqual({});
- expect(computed.computeMethod).toBeUndefined();
+ expect(computed.computeValueMethod).toBeUndefined();
+ expect(computed.computeExistsMethod).toBeInstanceOf(Function);
expect(computed.isPersisted).toBeFalsy();
expect(computed.persistent).toBeUndefined();
expect(computed.watchers).toStrictEqual({});
@@ -56,7 +57,7 @@ describe('Computed Tests', () => {
const computed = new Computed(dummyAgile, computedFunction, {
key: 'coolComputed',
dependents: [dummyObserver1],
- computedDeps: [dummyObserver2, undefined, dummyState],
+ computedDeps: [dummyObserver2, undefined as any, dummyState],
});
expect(computed.computeFunction).toBe(computedFunction);
@@ -78,7 +79,8 @@ describe('Computed Tests', () => {
expect(computed.observer.dependents.has(dummyObserver1)).toBeTruthy(); // x
expect(computed.observer._key).toBe('coolComputed'); // x
expect(computed.sideEffects).toStrictEqual({});
- expect(computed.computeMethod).toBeUndefined();
+ expect(computed.computeValueMethod).toBeUndefined();
+ expect(computed.computeExistsMethod).toBeInstanceOf(Function);
expect(computed.isPersisted).toBeFalsy();
expect(computed.persistent).toBeUndefined();
expect(computed.watchers).toStrictEqual({});
@@ -215,7 +217,7 @@ describe('Computed Tests', () => {
});
});
- describe('computeValue function tests', () => {
+ describe('compute function tests', () => {
let dummyObserver1: Observer;
let dummyObserver2: Observer;
let dummyObserver3: Observer;
@@ -240,7 +242,7 @@ describe('Computed Tests', () => {
dummyObserver2,
]);
- const response = computed.computeValue();
+ const response = computed.compute();
expect(response).toBe('newComputedValue');
expect(dummyComputeFunction).toHaveBeenCalled();
diff --git a/packages/core/tests/unit/integrations/integrations.test.ts b/packages/core/tests/unit/integrations/integrations.test.ts
index a22ee088..660ed3f9 100644
--- a/packages/core/tests/unit/integrations/integrations.test.ts
+++ b/packages/core/tests/unit/integrations/integrations.test.ts
@@ -88,7 +88,7 @@ describe('Integrations Tests', () => {
});
it("shouldn't integrate Integration that has no valid Key", async () => {
- dummyIntegration1._key = undefined;
+ dummyIntegration1._key = undefined as any;
const response = await integrations.integrate(dummyIntegration1);
diff --git a/packages/core/tests/unit/state/state.observer.test.ts b/packages/core/tests/unit/state/state.observer.test.ts
index ce2a081c..422c8fe5 100644
--- a/packages/core/tests/unit/state/state.observer.test.ts
+++ b/packages/core/tests/unit/state/state.observer.test.ts
@@ -121,7 +121,7 @@ describe('StateObserver Tests', () => {
});
it('should call ingestValue with computedValue if Observer belongs to a ComputedState (default config)', () => {
- dummyComputed.computeValue = jest.fn(() => 'computedValue');
+ dummyComputed.compute = jest.fn(() => 'computedValue');
computedObserver.ingest();
@@ -129,7 +129,7 @@ describe('StateObserver Tests', () => {
'computedValue',
{}
);
- expect(dummyComputed.computeValue).toHaveBeenCalled();
+ expect(dummyComputed.compute).toHaveBeenCalled();
});
});
@@ -265,7 +265,7 @@ describe('StateObserver Tests', () => {
});
it('should ingest State into Runtime and compute newStateValue if State compute Function is set (default config)', () => {
- dummyState.computeMethod = (value) => `cool value '${value}'`;
+ dummyState.computeValueMethod = (value) => `cool value '${value}'`;
stateObserver.ingestValue('updatedDummyValue');
@@ -351,8 +351,7 @@ describe('StateObserver Tests', () => {
describe('sideEffects function tests', () => {
let dummyJob: StateRuntimeJob;
- let dummyStateObserver: StateObserver;
- let sideEffectCallOrder = [];
+ let sideEffectCallOrder: string[] = [];
beforeEach(() => {
sideEffectCallOrder = [];
diff --git a/packages/core/tests/unit/state/state.persistent.test.ts b/packages/core/tests/unit/state/state.persistent.test.ts
index ea3d5f66..0bbdb1e7 100644
--- a/packages/core/tests/unit/state/state.persistent.test.ts
+++ b/packages/core/tests/unit/state/state.persistent.test.ts
@@ -26,6 +26,7 @@ describe('StatePersistent Tests', () => {
jest
.spyOn(StatePersistent.prototype, 'instantiatePersistent')
.mockImplementationOnce(function () {
+ // @ts-ignore
this.ready = false;
});
@@ -52,6 +53,7 @@ describe('StatePersistent Tests', () => {
jest
.spyOn(StatePersistent.prototype, 'instantiatePersistent')
.mockImplementationOnce(function () {
+ // @ts-ignore
this.ready = false;
});
@@ -80,6 +82,7 @@ describe('StatePersistent Tests', () => {
jest
.spyOn(StatePersistent.prototype, 'instantiatePersistent')
.mockImplementationOnce(function () {
+ // @ts-ignore
this.ready = true;
});
@@ -93,6 +96,7 @@ describe('StatePersistent Tests', () => {
jest
.spyOn(StatePersistent.prototype, 'instantiatePersistent')
.mockImplementationOnce(function () {
+ // @ts-ignore
this.ready = true;
});
diff --git a/packages/core/tests/unit/state/state.test.ts b/packages/core/tests/unit/state/state.test.ts
index da41eff3..6fcb651a 100644
--- a/packages/core/tests/unit/state/state.test.ts
+++ b/packages/core/tests/unit/state/state.test.ts
@@ -25,7 +25,7 @@ describe('State Tests', () => {
it('should create State and should call initial set (default config)', () => {
// Overwrite select once to not call it
- jest.spyOn(State.prototype, 'set').mockReturnValueOnce(undefined);
+ jest.spyOn(State.prototype, 'set').mockReturnValueOnce(undefined as any);
const state = new State(dummyAgile, 'coolValue');
@@ -42,7 +42,8 @@ describe('State Tests', () => {
expect(state.observer.dependents.size).toBe(0);
expect(state.observer._key).toBeUndefined();
expect(state.sideEffects).toStrictEqual({});
- expect(state.computeMethod).toBeUndefined();
+ expect(state.computeValueMethod).toBeUndefined();
+ expect(state.computeExistsMethod).toBeInstanceOf(Function);
expect(state.isPersisted).toBeFalsy();
expect(state.persistent).toBeUndefined();
expect(state.watchers).toStrictEqual({});
@@ -50,7 +51,7 @@ describe('State Tests', () => {
it('should create State and should call initial set (specific config)', () => {
// Overwrite select once to not call it
- jest.spyOn(State.prototype, 'set').mockReturnValueOnce(undefined);
+ jest.spyOn(State.prototype, 'set').mockReturnValueOnce(undefined as any);
const dummyObserver = new Observer(dummyAgile);
@@ -73,7 +74,8 @@ describe('State Tests', () => {
expect(state.observer.dependents.has(dummyObserver)).toBeTruthy();
expect(state.observer._key).toBe('coolState');
expect(state.sideEffects).toStrictEqual({});
- expect(state.computeMethod).toBeUndefined();
+ expect(state.computeValueMethod).toBeUndefined();
+ expect(state.computeExistsMethod).toBeInstanceOf(Function);
expect(state.isPersisted).toBeFalsy();
expect(state.persistent).toBeUndefined();
expect(state.watchers).toStrictEqual({});
@@ -81,7 +83,7 @@ describe('State Tests', () => {
it("should create State and shouldn't call initial set (config.isPlaceholder = true)", () => {
// Overwrite select once to not call it
- jest.spyOn(State.prototype, 'set').mockReturnValueOnce(undefined);
+ jest.spyOn(State.prototype, 'set').mockReturnValueOnce(undefined as any);
const state = new State(dummyAgile, 'coolValue', { isPlaceholder: true });
@@ -98,7 +100,8 @@ describe('State Tests', () => {
expect(state.observer.dependents.size).toBe(0);
expect(state.observer._key).toBeUndefined();
expect(state.sideEffects).toStrictEqual({});
- expect(state.computeMethod).toBeUndefined();
+ expect(state.computeValueMethod).toBeUndefined();
+ expect(state.computeExistsMethod).toBeInstanceOf(Function);
expect(state.isPersisted).toBeFalsy();
expect(state.persistent).toBeUndefined();
expect(state.watchers).toStrictEqual({});
@@ -179,33 +182,35 @@ describe('State Tests', () => {
});
it('should update existing Key in all instances', () => {
- numberState.persistent._key = 'numberStateKey';
+ if (numberState.persistent)
+ numberState.persistent._key = 'numberStateKey';
numberState.setKey('newKey');
expect(numberState._key).toBe('newKey');
expect(numberState.observer._key).toBe('newKey');
- expect(numberState.persistent.setKey).toHaveBeenCalledWith('newKey');
+ expect(numberState.persistent?.setKey).toHaveBeenCalledWith('newKey');
});
it("should update existing Key in all instances except persistent if the StateKey and PersistKey aren't equal", () => {
- numberState.persistent._key = 'randomKey';
+ if (numberState.persistent) numberState.persistent._key = 'randomKey';
numberState.setKey('newKey');
expect(numberState._key).toBe('newKey');
expect(numberState.observer._key).toBe('newKey');
- expect(numberState.persistent.setKey).not.toHaveBeenCalled();
+ expect(numberState.persistent?.setKey).not.toHaveBeenCalled();
});
it('should update existing Key in all instances except persistent if new StateKey is undefined', () => {
- numberState.persistent._key = 'numberStateKey';
+ if (numberState.persistent)
+ numberState.persistent._key = 'numberStateKey';
numberState.setKey(undefined);
expect(numberState._key).toBeUndefined();
expect(numberState.observer._key).toBeUndefined();
- expect(numberState.persistent.setKey).not.toHaveBeenCalled();
+ expect(numberState.persistent?.setKey).not.toHaveBeenCalled();
});
});
@@ -739,16 +744,51 @@ describe('State Tests', () => {
});
describe('exists get function tests', () => {
- it('should return true if State is no placeholder', () => {
+ it('should return true if State is no placeholder and computeExistsMethod returns true', () => {
+ numberState.computeExistsMethod = jest.fn().mockReturnValueOnce(true);
numberState.isPlaceholder = false;
expect(numberState.exists).toBeTruthy();
+ expect(numberState.computeExistsMethod).toHaveBeenCalledWith(
+ numberState.value
+ );
+ });
+
+ it('should return false if State is no placeholder and computeExistsMethod returns false', () => {
+ numberState.computeExistsMethod = jest.fn().mockReturnValueOnce(false);
+ numberState.isPlaceholder = false;
+
+ expect(numberState.exists).toBeFalsy();
+ expect(numberState.computeExistsMethod).toHaveBeenCalledWith(
+ numberState.value
+ );
});
it('should return false if State is placeholder"', () => {
+ numberState.computeExistsMethod = jest.fn(() => true);
numberState.isPlaceholder = true;
expect(numberState.exists).toBeFalsy();
+ expect(numberState.computeExistsMethod).not.toHaveBeenCalled(); // since isPlaceholder gets checked first
+ });
+ });
+
+ describe('computeExists function tests', () => {
+ it('should assign passed function to computeExistsMethod', () => {
+ const computeMethod = (value) => value === null;
+
+ numberState.computeExists(computeMethod);
+
+ expect(numberState.computeExistsMethod).toBe(computeMethod);
+ });
+
+ it("shouldn't assign passed invalid function to computeExistsMethod", () => {
+ numberState.computeExists(10 as any);
+
+ expect(numberState.computeExistsMethod).toBeInstanceOf(Function);
+ expect(console.error).toHaveBeenCalledWith(
+ "Agile Error: A 'computeExistsMethod' has to be a function!"
+ );
});
});
@@ -814,21 +854,27 @@ describe('State Tests', () => {
});
});
- describe('compute function tests', () => {
- it('should assign passed function to computeMethod', () => {
+ describe('computeValue function tests', () => {
+ beforeEach(() => {
+ numberState.set = jest.fn();
+ });
+
+ it('should assign passed function to computeValueMethod and compute State value initially', () => {
const computeMethod = () => 10;
- numberState.compute(computeMethod);
+ numberState.computeValue(computeMethod);
- expect(numberState.computeMethod).toBe(computeMethod);
+ expect(numberState.set).toHaveBeenCalledWith(10);
+ expect(numberState.computeValueMethod).toBe(computeMethod);
});
- it("shouldn't assign passed invalid function to computeMethod", () => {
- numberState.compute(10 as any);
+ it("shouldn't assign passed invalid function to computeValueMethod", () => {
+ numberState.computeValue(10 as any);
- expect(numberState.computeMethod).toBeUndefined();
+ expect(numberState.set).not.toHaveBeenCalled();
+ expect(numberState.computeValueMethod).toBeUndefined();
expect(console.error).toHaveBeenCalledWith(
- 'Agile Error: A computeMethod has to be a function!'
+ "Agile Error: A 'computeValueMethod' has to be a function!"
);
});
});
diff --git a/packages/core/tests/unit/storages/persistent.test.ts b/packages/core/tests/unit/storages/persistent.test.ts
index 39a11a4d..998e109a 100644
--- a/packages/core/tests/unit/storages/persistent.test.ts
+++ b/packages/core/tests/unit/storages/persistent.test.ts
@@ -139,7 +139,7 @@ describe('Persistent Tests', () => {
persistent.key = Persistent.placeHolderKey;
persistent.defaultStorageKey = undefined;
persistent.storageKeys = [];
- persistent.ready = undefined;
+ persistent.ready = undefined as any;
});
it('should return false and print error if no set key and no set StorageKeys', () => {
diff --git a/packages/core/tests/unit/storages/storage.test.ts b/packages/core/tests/unit/storages/storage.test.ts
index 9cf1d7af..c13e2819 100644
--- a/packages/core/tests/unit/storages/storage.test.ts
+++ b/packages/core/tests/unit/storages/storage.test.ts
@@ -129,7 +129,7 @@ describe('Storage Tests', () => {
});
it("should return false if get method isn't valid", () => {
- storage.methods.get = undefined;
+ storage.methods.get = undefined as any;
const response = storage.validate();
@@ -140,7 +140,7 @@ describe('Storage Tests', () => {
});
it("should return false if set method isn't valid", () => {
- storage.methods.set = undefined;
+ storage.methods.set = undefined as any;
const response = storage.validate();
@@ -151,7 +151,7 @@ describe('Storage Tests', () => {
});
it("should return false if remove method isn't valid", () => {
- storage.methods.remove = undefined;
+ storage.methods.remove = undefined as any;
const response = storage.validate();
diff --git a/packages/core/tests/unit/storages/storages.test.ts b/packages/core/tests/unit/storages/storages.test.ts
index b6adc84a..aad3e4cb 100644
--- a/packages/core/tests/unit/storages/storages.test.ts
+++ b/packages/core/tests/unit/storages/storages.test.ts
@@ -382,7 +382,7 @@ describe('Storages Tests', () => {
});
it('should return false if no instance of localStorage exits', () => {
- global.localStorage = undefined;
+ global.localStorage = undefined as any;
expect(Storages.localStorageAvailable()).toBeFalsy();
});
diff --git a/packages/core/tests/unit/utils.test.ts b/packages/core/tests/unit/utils.test.ts
index 739c5f28..5323928c 100644
--- a/packages/core/tests/unit/utils.test.ts
+++ b/packages/core/tests/unit/utils.test.ts
@@ -17,7 +17,6 @@ import {
getAgileInstance,
Agile,
State,
- Event,
Observer,
Collection,
createArrayFromObject,
@@ -208,12 +207,6 @@ describe('Utils Tests', () => {
expect(getAgileInstance(dummyState)).toBe(dummyAgile);
});
- it('should get agileInstance from Event', () => {
- const dummyEvent = new Event(dummyAgile);
-
- expect(getAgileInstance(dummyEvent)).toBe(dummyAgile);
- });
-
it('should get agileInstance from Collection', () => {
const dummyCollection = new Collection(dummyAgile);
diff --git a/packages/cra-template-agile-typescript/template.json b/packages/cra-template-agile-typescript/template.json
index e55043ae..66fb64e8 100644
--- a/packages/cra-template-agile-typescript/template.json
+++ b/packages/cra-template-agile-typescript/template.json
@@ -6,8 +6,7 @@
"@testing-library/user-event": "^12.1.10",
"web-vitals": "^1.0.1",
"@agile-ts/core": "^0.0.10",
- "@agile-ts/react": "^0.0.10",
- "@agile-ts/api": "^0.0.10"
+ "@agile-ts/react": "^0.0.10"
},
"eslintConfig": {
"extends": ["react-app", "react-app/jest"]
diff --git a/packages/cra-template-agile/template.json b/packages/cra-template-agile/template.json
index e55043ae..66fb64e8 100644
--- a/packages/cra-template-agile/template.json
+++ b/packages/cra-template-agile/template.json
@@ -6,8 +6,7 @@
"@testing-library/user-event": "^12.1.10",
"web-vitals": "^1.0.1",
"@agile-ts/core": "^0.0.10",
- "@agile-ts/react": "^0.0.10",
- "@agile-ts/api": "^0.0.10"
+ "@agile-ts/react": "^0.0.10"
},
"eslintConfig": {
"extends": ["react-app", "react-app/jest"]
diff --git a/packages/api/CHANGELOG.md b/packages/event/CHANGELOG.md
similarity index 100%
rename from packages/api/CHANGELOG.md
rename to packages/event/CHANGELOG.md
diff --git a/packages/event/LICENSE b/packages/event/LICENSE
new file mode 100644
index 00000000..b93156fb
--- /dev/null
+++ b/packages/event/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2020-present bennodev19
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/packages/event/README.md b/packages/event/README.md
new file mode 100644
index 00000000..2734ba23
--- /dev/null
+++ b/packages/event/README.md
@@ -0,0 +1,42 @@
+# [WIP] Event
+
+> Handy class for emitting UI Events
+
+
+
+
+
+
+
+
+
+
+
+
+
+## ⏰ Short Example
+```ts
+const App = new Agile();
+const MY_EVENT = new Event(App);
+MY_EVENT.on((data) => {console.log("hello there " + data.name)}); // Print 'hello there jeff' if Event gets triggered
+MY_EVENT.trigger({name: "jeff"}); // Trigger Event
+```
+
+
+## ⬇️ Installation
+```
+npm install @agile-ts/event
+```
+The `event` package is an extension of AgileTs for React, which doesn't work without the [`core`](https://agile-ts.org/docs/core)
+and [`react`](https://agile-ts.org/docs/react) package.
+Unfortunately, we can't combine each `core`, `react` with `event` version.
+Therefore, we have created a table which shows which versions fit together without restrictions.
+
+| @agile-ts/event | @agile-ts/core | @agile-ts/event | NPM Version | Supported React versions | Supports hook based components |
+| ----------------------| ----------------------- | ------------------------ | ------------------------ | -------------------------|---------------------------------- |
+| v0.0.1+ | v0.0.10+ | v0.0.10+ | v6+ | 16.8+ | Yes |
+_Other Versions aren't supported anymore_
+
+
+## 📄 Documentation
+The Agile Event Docs are located [here](https://agile-ts.org/docs/)
\ No newline at end of file
diff --git a/packages/event/jest.config.js b/packages/event/jest.config.js
new file mode 100644
index 00000000..e7c8d896
--- /dev/null
+++ b/packages/event/jest.config.js
@@ -0,0 +1,7 @@
+const baseConfig = require('../../jest.config.base');
+
+module.exports = {
+ ...baseConfig,
+ rootDir: '../..',
+ name: 'Event',
+};
diff --git a/packages/event/package.json b/packages/event/package.json
new file mode 100644
index 00000000..c4e3f44e
--- /dev/null
+++ b/packages/event/package.json
@@ -0,0 +1,48 @@
+{
+ "name": "@agile-ts/event",
+ "version": "0.0.1",
+ "author": "BennoDev",
+ "license": "MIT",
+ "homepage": "https://agile-ts.org/",
+ "description": "Handy class for emitting UI updates and passing data with them",
+ "keywords": [
+ "agile",
+ "agile-ts",
+ "event",
+ "ui-event"
+ ],
+ "main": "dist/index.js",
+ "types": "dist/index.d.ts",
+ "scripts": {
+ "build": "tsc",
+ "prepare": "tsc && tsc -p ./tsconfig.production.json",
+ "dev:publish": "yalc publish",
+ "dev:push": "yalc push",
+ "watch": "tsc-watch --onSuccess \"yarn run dev:push\"",
+ "release": "yarn run prepare",
+ "preview": "npm pack"
+ },
+ "devDependencies": {
+ "@agile-ts/core": "file:../core",
+ "@agile-ts/react": "file:../react",
+ "@types/react": "^17.0.0",
+ "react": "^17.0.1"
+ },
+ "peerDependencies": {
+ "react": "^16.13.1",
+ "@agile-ts/core": "^0.0.12",
+ "@agile-ts/react": "^0.0.12"
+ },
+ "publishConfig": {
+ "access": "public"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/agile-ts/agile.git"
+ },
+ "files": [
+ "dist",
+ "LICENSE",
+ "README.md"
+ ]
+}
diff --git a/packages/core/src/event/event.job.ts b/packages/event/src/event.job.ts
similarity index 100%
rename from packages/core/src/event/event.job.ts
rename to packages/event/src/event.job.ts
diff --git a/packages/core/src/event/event.observer.ts b/packages/event/src/event.observer.ts
similarity index 95%
rename from packages/core/src/event/event.observer.ts
rename to packages/event/src/event.observer.ts
index 5780c98b..97da3216 100644
--- a/packages/core/src/event/event.observer.ts
+++ b/packages/event/src/event.observer.ts
@@ -2,9 +2,9 @@ import {
Observer,
RuntimeJob,
ObserverKey,
- Event,
SubscriptionContainer,
-} from '../internal';
+} from '@agile-ts/core';
+import { Event } from './internal';
export class EventObserver extends Observer {
public event: () => Event;
diff --git a/packages/core/src/event/index.ts b/packages/event/src/event.ts
similarity index 99%
rename from packages/core/src/event/index.ts
rename to packages/event/src/event.ts
index 7867752a..3e4a1c55 100644
--- a/packages/core/src/event/index.ts
+++ b/packages/event/src/event.ts
@@ -1,12 +1,11 @@
import {
Agile,
defineConfig,
- EventJob,
generateId,
isFunction,
Observer,
-} from '../internal';
-import { EventObserver } from './event.observer';
+} from '@agile-ts/core';
+import { EventObserver, EventJob } from './internal';
export class Event {
public agileInstance: () => Agile;
diff --git a/packages/react/src/hooks/useEvent.ts b/packages/event/src/hooks/useEvent.ts
similarity index 90%
rename from packages/react/src/hooks/useEvent.ts
rename to packages/event/src/hooks/useEvent.ts
index 895eca97..6aef1f5c 100644
--- a/packages/react/src/hooks/useEvent.ts
+++ b/packages/event/src/hooks/useEvent.ts
@@ -1,12 +1,11 @@
import React from 'react';
import {
Agile,
- Event,
- EventCallbackFunction,
getAgileInstance,
SubscriptionContainerKeyType,
} from '@agile-ts/core';
-import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect';
+import { Event, EventCallbackFunction } from '../internal';
+import { useIsomorphicLayoutEffect } from '@agile-ts/react';
export function useEvent>(
event: E,
diff --git a/packages/event/src/index.ts b/packages/event/src/index.ts
new file mode 100644
index 00000000..f3396fb7
--- /dev/null
+++ b/packages/event/src/index.ts
@@ -0,0 +1,5 @@
+import { Event } from './internal';
+
+export * from './internal';
+export { useEvent } from './hooks/useEvent';
+export default Event;
diff --git a/packages/event/src/internal.ts b/packages/event/src/internal.ts
new file mode 100644
index 00000000..e63a1ffb
--- /dev/null
+++ b/packages/event/src/internal.ts
@@ -0,0 +1,9 @@
+// This file exposes Agile Editor functions and types to the outside world
+// It also serves as a cyclic dependency workaround
+// https://medium.com/visual-development/how-to-fix-nasty-circular-dependency-issues-once-and-for-all-in-javascript-typescript-a04c987cf0de.
+
+// !! All internal Agile Editor modules must be imported from here!!
+
+export * from './event.job';
+export * from './event.observer';
+export * from './event';
diff --git a/packages/core/tests/unit/event/event.job.test.ts b/packages/event/tests/unit/event.job.test.ts
similarity index 95%
rename from packages/core/tests/unit/event/event.job.test.ts
rename to packages/event/tests/unit/event.job.test.ts
index fa066972..2ceb962c 100644
--- a/packages/core/tests/unit/event/event.job.test.ts
+++ b/packages/event/tests/unit/event.job.test.ts
@@ -1,4 +1,4 @@
-import { EventJob } from '../../../src';
+import { EventJob } from '../../src';
describe('EventJob Tests', () => {
it('should create EventJob (without keys)', () => {
diff --git a/packages/core/tests/unit/event/event.observer.test.ts b/packages/event/tests/unit/event.observer.test.ts
similarity index 94%
rename from packages/core/tests/unit/event/event.observer.test.ts
rename to packages/event/tests/unit/event.observer.test.ts
index 8a34af06..2760361b 100644
--- a/packages/core/tests/unit/event/event.observer.test.ts
+++ b/packages/event/tests/unit/event.observer.test.ts
@@ -1,11 +1,5 @@
-import {
- EventObserver,
- Agile,
- Observer,
- SubscriptionContainer,
- Event,
- RuntimeJob,
-} from '../../../src';
+import { EventObserver, Event } from '../../src';
+import { Agile, Observer, SubscriptionContainer } from '@agile-ts/core';
describe('EventObserver Tests', () => {
let dummyAgile: Agile;
diff --git a/packages/core/tests/unit/event/event.test.ts b/packages/event/tests/unit/event.test.ts
similarity index 97%
rename from packages/core/tests/unit/event/event.test.ts
rename to packages/event/tests/unit/event.test.ts
index 8fb38f6a..3800cc63 100644
--- a/packages/core/tests/unit/event/event.test.ts
+++ b/packages/event/tests/unit/event.test.ts
@@ -1,5 +1,6 @@
-import { Event, Agile, Observer, EventObserver } from '../../../src';
-import * as Utils from '../../../src/utils';
+import { Event, EventObserver } from '../../src';
+import { Agile, Observer } from '@agile-ts/core';
+import * as Utils from '@agile-ts/core/dist/utils';
describe('Event Tests', () => {
let dummyAgile: Agile;
@@ -200,7 +201,7 @@ describe('Event Tests', () => {
describe('disable function tests', () => {
it('should disable Event', () => {
- event.enabled = undefined;
+ event.enabled = undefined as any;
event.disable();
@@ -210,7 +211,7 @@ describe('Event Tests', () => {
describe('enable function tests', () => {
it('should enable Event', () => {
- event.enabled = undefined;
+ event.enabled = undefined as any;
event.enable();
@@ -226,7 +227,7 @@ describe('Event Tests', () => {
// @ts-ignore
// eslint-disable-next-line no-global-assign
clearTimeout = jest.fn();
- event.enabled = undefined;
+ event.enabled = undefined as any;
event.uses = 100;
event.currentTimeout = timeout;
diff --git a/packages/event/tsconfig.json b/packages/event/tsconfig.json
new file mode 100644
index 00000000..600cd205
--- /dev/null
+++ b/packages/event/tsconfig.json
@@ -0,0 +1,10 @@
+{
+ "extends": "../tsconfig.default.json",
+ "compilerOptions": {
+ "rootDir": "src",
+ "outDir": "dist"
+ },
+ "include": [
+ "./src/**/*" // Only include what is in src (-> dist, tests, .. will be excluded)
+ ]
+}
\ No newline at end of file
diff --git a/packages/event/tsconfig.production.json b/packages/event/tsconfig.production.json
new file mode 100644
index 00000000..4b5c4d12
--- /dev/null
+++ b/packages/event/tsconfig.production.json
@@ -0,0 +1,7 @@
+{
+ "extends": "./tsconfig.json",
+ "compilerOptions": {
+ "declaration": false,
+ "removeComments": true
+ }
+}
\ No newline at end of file
diff --git a/packages/multieditor/README.md b/packages/multieditor/README.md
index f46aaff5..ede5cabd 100644
--- a/packages/multieditor/README.md
+++ b/packages/multieditor/README.md
@@ -13,6 +13,7 @@
+
## ⏰ Short Example
```ts
// Let's create our MultiEditor
@@ -47,6 +48,7 @@ multiEditor.submit();
```
_Do you want to see it in action? Click [here](https://codesandbox.io/s/multieditor-yxt4x)._
+
## ❓ Why Agile MultiEditor
#### 🚅 Straightforward
@@ -65,28 +67,31 @@ Write minimalistic, boilerplate free code that captures your intent.
}
```
+
#### 🎯 Easy to Use
Learn the powerful and simple tools of Agile MultiEditor in a short amount of time.
+
#### 🍃 Lightweight
Agile Api has an unpacked size of [14.1kB](https://bundlephobia.com/result?p=@agile-ts/multieditor@0.0.6)
and [0 external dependencies](https://www.npmjs.com/package/@agile-ts/multieditor).
+
## ⬇️ Installation
```
npm install @agile-ts/multieditor
```
-_Be aware that this is no standalone package!_
-To use the Agile MultiEditor you have to install the [Agile Core](https://www.npmjs.com/package/@agile-ts/core).
-To find out more take a look into the [docs](https://www.agile-ts.org/docs).
-
-
-## 🔑 Fitting Versions
-| @agile-ts/api | @agile-ts/core | NPM Version |
-| --------------- | ----------------------- | ------------------------ |
-| v0.0.7 | v0.0.7+ | v6+ |
-| v0.0.6 | v0.0.6 | v6+ |
+The `multieditor` package is an extension of AgileTs and doesn't work without the [`core`](https://agile-ts.org/docs/core) package,
+which functions as the brain of AgileTs and is indispensable.
+Unfortunately, we can't combine each `core` with `multieditor` version.
+Therefore, we have created a table which shows which versions fit together without restrictions.
+
+| @agile-ts/multieditor | @agile-ts/core | NPM Version |
+| ----------------------| ----------------------- | ------------------------ |
+| v0.0.7+ | v0.0.7+ | v6+ |
+| v0.0.6 | v0.0.3 - v0.0.6 | v6+ |
_Other Versions aren't supported anymore_
+
## 📄 Documentation
-The Agile Api Docs are located [here](https://agile-ts.org/docs/)
+The Agile MultiEditor Docs are located [here](https://agile-ts.org/docs/)
diff --git a/packages/multieditor/jest.config.js b/packages/multieditor/jest.config.js
index a7382750..9852e7e8 100644
--- a/packages/multieditor/jest.config.js
+++ b/packages/multieditor/jest.config.js
@@ -3,5 +3,5 @@ const baseConfig = require('../../jest.config.base');
module.exports = {
...baseConfig,
rootDir: '../..',
- name: 'Multi Editor',
+ name: 'MultiEditor',
};
diff --git a/packages/multieditor/package.json b/packages/multieditor/package.json
index 09bd0980..af294ba4 100644
--- a/packages/multieditor/package.json
+++ b/packages/multieditor/package.json
@@ -19,9 +19,9 @@
"scripts": {
"build": "tsc",
"prepare": "tsc && tsc -p ./tsconfig.production.json",
- "dev-publish": "yalc publish",
- "dev-push": "yalc push",
- "watch": "tsc-watch --onSuccess \"yarn run dev-push\"",
+ "dev:publish": "yalc publish",
+ "dev:push": "yalc push",
+ "watch": "tsc-watch --onSuccess \"yarn run dev:push\"",
"release": "yarn run prepare",
"preview": "npm pack"
},
diff --git a/packages/multieditor/src/multieditor.ts b/packages/multieditor/src/multieditor.ts
index 15c69268..573ca0ce 100644
--- a/packages/multieditor/src/multieditor.ts
+++ b/packages/multieditor/src/multieditor.ts
@@ -1,6 +1,6 @@
import {
Agile,
- ComputeMethod,
+ ComputeValueMethod,
copy,
defineConfig,
getAgileInstance,
@@ -30,7 +30,7 @@ export class MultiEditor<
public validateMethods: DataObject<
ValidationMethodInterface | Validator
> = {};
- public computeMethods: DataObject> = {};
+ public computeMethods: DataObject> = {};
public onSubmit: (
preparedData: DataObject,
config?: OnSubmitConfigType
@@ -85,7 +85,7 @@ export class MultiEditor<
item.validate();
if (Object.prototype.hasOwnProperty.call(this.computeMethods, key)) {
const computeMethod = this.computeMethods[key];
- item.compute(computeMethod);
+ item.computeValue(computeMethod);
}
}
}
@@ -514,7 +514,7 @@ export interface CreateEditorConfigInterface<
validateMethods?: DataObject<
ValidationMethodInterface | Validator
>;
- computeMethods?: DataObject>;
+ computeMethods?: DataObject>;
onSubmit: (
preparedData: DataObject,
config?: onSubmitConfig
diff --git a/packages/react/README.md b/packages/react/README.md
index f8af4676..4f690a8c 100644
--- a/packages/react/README.md
+++ b/packages/react/README.md
@@ -1,6 +1,6 @@
-> **Use AgileTs with React and React-Native**
+> Integrate AgileTs into React or React-Native
@@ -20,22 +20,40 @@
-Well, the main task of this Integration is to bind States, Collection, .. to React Components.
-This binding ensures that AgileTs rerender the Component, if a bound Instance mutates.
-It also offers some other useful functions that optimize the workflow of AgileTs in React.
+The `react` package is an Integration of AgileTs into React.
+Its main task is to bind States to React Components.
+This binding ensures that AgileTs rerender the Component, whenever a bound State mutates.
+It also offers some other useful functions that optimize the workflow with AgileTs in a React Environment.
-Here is a quick example how such a binding might look like:
+A distinction is made between `Functional` and `Class` Components,
+as we prefer using `React Hooks` in Functional Components.
+But Hooks aren't supported in Class Components, so we came across other solutions,
+to offer the same features there too.
+
+### 🐆 Functional Component
+In Function Components we recommend using AgileTs Hooks like `useAgile`,
+which allows us to bind any State to our React Component
```ts
// -- myComponent.jsx ------------------------------------------
-// Binds MY_FIRST_STATE to myComponent.jsx
- const myFirstState = useAgile(MY_FIRST_STATE);
+// Binds MY_FIRST_STATE to myComponent
+const myFirstState = useAgile(MY_FIRST_STATE);
```
+To find out more about `useAgile`, and other Hooks provided by AgileTs,
+checkout the AgileTs Hook [docs](https://agile-ts.org/docs/react/hooks).
-A distinction is made between `Functional` and `Class` Components,
-as we prefer using `React Hooks` in Functional Components.
-But Hooks aren't supported in Class Components, so we came across other solutions,
-to offer the same features there too.
+### 🦖 Class Component
+In Class Component we currently only support the `AgileHOC`,
+which helps us binding States to our Component.
+It is a Higher order Component that gets wrapped around our React Component.
+```ts
+// -- myComponent.jsx ------------------------------------------
+
+// Binds MY_FIRST_STATE to myComponent
+export default AgileHOC(myComponent, [MY_FIRST_STATE]);
+```
+To find out more AgileTs in Class Components,
+checkout the AgileHOC [docs](https://agile-ts.org/docs/react/AgileHOC).
@@ -47,12 +65,10 @@ to offer the same features there too.
```
npm install @agile-ts/react
```
-_Be aware that this is no standalone package!_
-
-The React Integration is only an extension of AgileTs and doesn't work without the [Core Package](https://www.npmjs.com/package/@agile-ts/core),
+The `react` package is an extension of AgileTs and doesn't work without the [`core`](https://agile-ts.org/docs/core) package,
which functions as the brain of AgileTs and is indispensable.
-Unfortunately, we can't combine every `core` version with `react` version.
-Therefore, you can find a table that shows which versions fit together below.
+Unfortunately, we can't combine each `core` with `react` version.
+Therefore, we have created a table which shows which versions fit together without restrictions.
| @agile-ts/react | @agile-ts/core | NPM Version | Supported React versions | Supports hook based components |
| --------------- | ----------------------- | ------------------------ | -------------------------|---------------------------------- |
@@ -60,8 +76,6 @@ Therefore, you can find a table that shows which versions fit together below.
| v0.0.6 | v0.0.3 - v0.0.6 | v6+ | 16.8+ | Yes |
_Other Versions aren't supported anymore_
-To find out more checkout our [docs](https://www.agile-ts.org/docs).
-
@@ -69,9 +83,8 @@ To find out more checkout our [docs](https://www.agile-ts.org/docs).
-If you want to find out more about the AgileTs React Integration.
-Checkout our **[docs](https://agile-ts.org/docs/react)**.
-In case you have any questions don't mind joining our [Discord Community](https://discord.gg/FTqeMNCxw7).
+Checkout our **[documentation](https://agile-ts.org/docs/introduction)**, to learn more.
+In case you have any further questions don't mind joining our [Community Discord](https://discord.gg/T9GzreAwPH).
@@ -80,5 +93,5 @@ In case you have any questions don't mind joining our [Discord Community](https:
-Get a part of AgileTs and start contributing. To find out more read the [CONTRIBUTING.md](https://github.com/agile-ts/agile/blob/master/CONTRIBUTING.md).
-
+Get a part of AgileTs and start contributing. We welcome any meaningful contribution 😀
+To find out more checkout the [CONTRIBUTING.md](https://github.com/agile-ts/agile/blob/master/CONTRIBUTING.md).
diff --git a/packages/react/package.json b/packages/react/package.json
index 8158db6d..fe9a7cc3 100644
--- a/packages/react/package.json
+++ b/packages/react/package.json
@@ -19,9 +19,9 @@
"scripts": {
"build": "tsc",
"prepare": "tsc && tsc -p ./tsconfig.production.json",
- "dev-publish": "yalc publish",
- "dev-push": "yalc push",
- "watch": "tsc-watch --onSuccess \"yarn run dev-push\"",
+ "dev:publish": "yalc publish",
+ "dev:push": "yalc push",
+ "watch": "tsc-watch --onSuccess \"yarn run dev:push\"",
"release": "yarn run prepare",
"preview": "npm pack"
},
diff --git a/packages/react/src/hooks/useAgile.ts b/packages/react/src/hooks/useAgile.ts
index 6c4947e6..31ca823a 100644
--- a/packages/react/src/hooks/useAgile.ts
+++ b/packages/react/src/hooks/useAgile.ts
@@ -9,7 +9,7 @@ import {
State,
SubscriptionContainerKeyType,
} from '@agile-ts/core';
-import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect';
+import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
//=========================================================================================================
// useAgile
diff --git a/packages/react/src/utils/useIsomorphicLayoutEffect.ts b/packages/react/src/hooks/useIsomorphicLayoutEffect.ts
similarity index 100%
rename from packages/react/src/utils/useIsomorphicLayoutEffect.ts
rename to packages/react/src/hooks/useIsomorphicLayoutEffect.ts
diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts
index 2a14fc56..ac70be1f 100644
--- a/packages/react/src/index.ts
+++ b/packages/react/src/index.ts
@@ -2,7 +2,7 @@ import reactIntegration from './react.integration';
export { useAgile } from './hooks/useAgile';
export { AgileHOC } from './other/AgileHOC';
-export { useEvent } from './hooks/useEvent';
export { useWatcher } from './hooks/useWatcher';
+export { useIsomorphicLayoutEffect } from './hooks/useIsomorphicLayoutEffect';
export default reactIntegration;
diff --git a/packages/react/src/other/AgileHOC.ts b/packages/react/src/other/AgileHOC.ts
index 855e464f..6a004b4b 100644
--- a/packages/react/src/other/AgileHOC.ts
+++ b/packages/react/src/other/AgileHOC.ts
@@ -122,7 +122,7 @@ const createHOC = (
this.agileProps = response.props;
// Merge depsWith Indicator into this.state
- this.state = flatMerge(this.state || {}, depsWithIndicator);
+ this.setState(flatMerge(this.state || {}, depsWithIndicator));
}
}
diff --git a/packages/react/tsconfig.json b/packages/react/tsconfig.json
index 8ecfe483..600cd205 100644
--- a/packages/react/tsconfig.json
+++ b/packages/react/tsconfig.json
@@ -7,5 +7,4 @@
"include": [
"./src/**/*" // Only include what is in src (-> dist, tests, .. will be excluded)
]
-
}
\ No newline at end of file
diff --git a/yarn.lock b/yarn.lock
index 6aa52288..aadeeb94 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3,7 +3,10 @@
"@agile-ts/core@file:packages/core":
- version "0.0.11"
+ version "0.0.12"
+
+"@agile-ts/react@file:packages/react":
+ version "0.0.12"
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.12.11":
version "7.12.11"