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

Commit 9c15f5c

Browse files
authored
Merge pull request #3 from agile-ts/develop
Develop
2 parents 5575f0e + 8a175f8 commit 9c15f5c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1039
-374
lines changed

.npmignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

ReadMe.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Agile Framework `1.0`
1+
# Agile Framework `1.0.2`
22

33
_Agile is a global state and logic framework for reactive Typescript & Javascript applications. Supporting frameworks like React and React Native._
44

55
#### Agile is strongly inspired by [PulseJs](https://github.com/pulse-framework/pulse)
66
It was mainly created to learn how Pulse works under the hood, and it was fun to 'copy' and optimize PulseJs.
7-
I will use this project mainly for my own project because here the code style is after my taste..
7+
I will use this project mainly for my own projects because here the code style is after my taste..
88
So I can change things quickly and don't have to deal with a big framework which is used by many people and must function perfectly.
99

10-
##### Feel free to use it but be aware that it is optimized to my needs and has no docs
10+
##### Feel free to use it but be aware that it is optimized to my needs and has no [docs](https://pulsejs.org/)
1111

1212
<div align="center">
1313
<img src="https://i.pinimg.com/originals/66/70/fd/6670fd61b91760bf8f04ca0479a2e0d1.gif">

examples/react-typescript/src/App.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import React from 'react';
2-
import logo from './logo.svg';
32
import './App.css';
4-
import {useAgile} from 'agile-framework';
5-
import {MY_COLLECTION, MY_COMPUTED, MY_STATE, MY_STATE_2} from "./core";
3+
import {useAgile, useEvent} from 'agile-framework';
4+
import {MY_COLLECTION, MY_COMPUTED, MY_EVENT, MY_STATE, MY_STATE_2} from "./core";
65

76
const App = (props: any) => {
87

98
const [myComputed] = useAgile([MY_COMPUTED]);
109
const [myState, myState2] = useAgile([MY_STATE, MY_STATE_2]);
1110
const [myCollection] = useAgile([MY_COLLECTION.getGroup('myGroup')]);
12-
const [mySelector] = useAgile([MY_COLLECTION.getSelector('mySelector')]);
11+
const mySelector = useAgile(MY_COLLECTION.getSelector('mySelector'));
1312

13+
useEvent(MY_EVENT, () => {
14+
console.log("Triggered Event");
15+
});
1416

1517
console.log("myComputed", MY_COMPUTED);
1618
console.log("myState", MY_STATE);
1719
console.log("myState2", MY_STATE_2);
1820
console.log("myCollection", MY_COLLECTION);
21+
console.log("myEvent", MY_EVENT);
1922

2023

2124
return (
@@ -47,6 +50,15 @@ const App = (props: any) => {
4750
</p>
4851
</div>
4952

53+
<div className={"Container"}>
54+
<h3 className={"Title"}>My Event</h3>
55+
<button onClick={() => setTimeout(() => {
56+
MY_EVENT.trigger({name: 'test'})
57+
}, 1000)}>
58+
Trigger
59+
</button>
60+
</div>
61+
5062
<div className={"Container"}>
5163
<h3 className={"Title"}>My Collection</h3>
5264
<div>
@@ -72,11 +84,11 @@ const App = (props: any) => {
7284
<button onClick={() => setTimeout(() => {
7385
MY_COLLECTION.remove("newId3").everywhere();
7486
}, 1000)}>
75-
Remove newId3
87+
Remove newId3
7688
</button>
7789
</div>
7890

79-
<p>MySelector: {mySelector.name}</p>
91+
<p>MySelector: {mySelector?.name}</p>
8092

8193
</header>
8294
</div>

examples/react-typescript/src/core/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ export const MY_COLLECTION = App.Collection<collectionValueInterface>(collection
3535
MY_COLLECTION.collect({id: 'id1', name: 'test'});
3636
MY_COLLECTION.collect({id: 'id2', name: 'test2'}, 'myGroup');
3737
console.log("Initial: myCollection ", MY_COLLECTION);
38+
39+
export const MY_EVENT = App.Event<{name: string}>();

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
{
2-
"name": "agile-framework",
3-
"version": "1.0.0",
2+
"name": "agile",
3+
"version": "1.0.2",
44
"description": "Global state and logic framework for reactive React applications.",
55
"main": "dist/index.js",
66
"module": "dist/index.js",
7+
"types": "./dist/index.d.ts",
78
"scripts": {
89
"build": "tsc",
910
"dev": "tsc-watch",
10-
"test": "mocha -r ts-node/register --exit test/**/*.spec.ts"
11+
"test": "mocha -r ts-node/register --exit test/**/*.spec.ts",
12+
"prepare": "npm run build",
13+
"prepublishOnly": "npm test",
14+
"version": "npm run format && git add -A src",
15+
"postversion": "git push && git push --tags"
1116
},
12-
"types": "./dist/index.d.ts",
17+
"repository": {
18+
"type": "git",
19+
"url": "git+https://github.com/agile-architecture/agile.git"
20+
},
21+
"keywords": [
22+
"React",
23+
"State-Management"
24+
],
1325
"author": "BennoDev",
1426
"license": "ISC",
1527
"dependencies": {
@@ -24,5 +36,8 @@
2436
"tsc-watch": "^4.1.0",
2537
"tslib": "^2.0.0",
2638
"typescript": "^3.9.7"
27-
}
39+
},
40+
"files": [
41+
"dist/**/*"
42+
]
2843
}

src/agile.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import Runtime from "./runtime";
22
import use, {Integration} from "./integrations/use";
33
import SubController from "./sub";
4-
import {State} from "./state";
4+
import State from "./state";
55
import Storage, {StorageConfigInterface} from "./storage";
6-
import {Collection, Config, DefaultDataItem} from "./collection";
7-
import {Computed} from "./computed";
8-
import API, {apiConfig} from "./api/api";
6+
import Collection, {CollectionConfig, DefaultDataItem} from "./collection";
7+
import Computed from "./computed";
8+
import API, {apiConfig} from "./api";
9+
import Event, {EventConfig, DefaultEventPayload} from "./event";
910

1011
export interface AgileConfigInterface {
1112
framework?: Integration | any // Integration = for custom frameworks | any = for existing frameworks like react
@@ -87,7 +88,7 @@ export default class Agile {
8788
/**
8889
* Create Agile Collection
8990
*/
90-
public Collection = <DataType = DefaultDataItem>(config?: Config<DataType>) => new Collection<DataType>(this, config);
91+
public Collection = <DataType = DefaultDataItem>(config?: CollectionConfig<DataType>) => new Collection<DataType>(this, config);
9192

9293

9394
//=========================================================================================================
@@ -98,7 +99,16 @@ export default class Agile {
9899
* @param deps Array - An array of state items to depend on
99100
* @param computeFunction Function - A function where the return value is the state, ran every time a dep changes
100101
*/
101-
public Computed = <T = any>(computeFunction: () => T, deps?: Array<State>) => new Computed<T>(this, computeFunction, deps);
102+
public Computed = <ComputedValueType = any>(computeFunction: () => ComputedValueType, deps?: Array<State>) => new Computed<ComputedValueType>(this, computeFunction, deps);
103+
104+
105+
//=========================================================================================================
106+
// Event
107+
//=========================================================================================================
108+
/**
109+
* Create a Pulse Event
110+
*/
111+
public Event = <PayloadType = DefaultEventPayload>(config?: EventConfig) => new Event<PayloadType>(this, config);
102112

103113

104114
//=========================================================================================================
File renamed without changes.

src/collection/group.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {Collection, DefaultDataItem, ItemKey} from "./index";
2-
import {State} from "../state";
1+
import Collection, {DefaultDataItem, ItemKey} from "./index";
2+
import State from "../state";
33
import Agile from "../agile";
44
import {defineConfig, normalizeArray} from "../utils";
55
import {updateGroup} from "./perstist";
@@ -16,7 +16,7 @@ export interface GroupConfigInterface {
1616
key?: GroupKey // should be a unique key/name which identifies the group
1717
}
1818

19-
export class Group<DataType = DefaultDataItem> extends State<Array<ItemKey>> {
19+
export default class Group<DataType = DefaultDataItem> extends State<Array<ItemKey>> {
2020
collection: () => Collection<DataType>;
2121

2222
_output: Array<DataType> = []; // Output of the group (Note: _value are only the keys of the collection items)

src/collection/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import Agile from "../agile";
22
import Item from "./item";
3-
import {Group, GroupConfigInterface, GroupKey} from "./group";
4-
import {Selector, SelectorKey} from "./selector";
3+
import Group, {GroupConfigInterface, GroupKey} from "./group";
4+
import Selector, {SelectorKey} from "./selector";
55
import {copy, defineConfig, flatMerge, isValidObject, normalizeArray} from "../utils";
6-
import {State, StateKey} from "../state";
6+
import State, {StateKey} from "../state";
77
import {StorageKey} from "../storage";
88
import {persistValue, removeItem, setItem} from "./perstist";
99

@@ -26,11 +26,11 @@ export interface CollectOptionsInterface<DataType = any> {
2626
background?: boolean // If the action should happen in the background -> no rerender
2727
}
2828

29-
export type Config<DataType = DefaultDataItem> =
29+
export type CollectionConfig<DataType = DefaultDataItem> =
3030
| CollectionConfigInterface
3131
| ((collection: Collection<DataType>) => CollectionConfigInterface);
3232

33-
export class Collection<DataType = DefaultDataItem> {
33+
export default class Collection<DataType = DefaultDataItem> {
3434
public agileInstance: () => Agile;
3535

3636
public config: CollectionConfigInterface;
@@ -43,7 +43,7 @@ export class Collection<DataType = DefaultDataItem> {
4343
public groups: { [key: string]: Group<any> } = {};
4444
public selectors: { [key: string]: Selector<any> } = {};
4545

46-
constructor(agileInstance: Agile, config: Config<DataType> = {}) {
46+
constructor(agileInstance: Agile, config: CollectionConfig<DataType> = {}) {
4747
this.agileInstance = () => agileInstance;
4848

4949
// If collection config is a function, execute and assign to config
@@ -61,10 +61,10 @@ export class Collection<DataType = DefaultDataItem> {
6161
// Set Key
6262
this._key = this.config.key;
6363

64-
// Create Groups
64+
// Init Groups
6565
this.initSubInstances('groups');
6666

67-
// Create Selectors
67+
// Init Selectors
6868
this.initSubInstances('selectors');
6969
}
7070

@@ -315,7 +315,7 @@ export class Collection<DataType = DefaultDataItem> {
315315
console.warn(`Agile: Group with name '${groupName}' doesn't exist!`);
316316

317317
// Return empty group because it might get annoying to handle with undefined (can check if it exists with group.exists)
318-
const group = new Group(this.agileInstance(), this, [], {key: 'dummy'});
318+
const group = new Group<DataType>(this.agileInstance(), this, [], {key: 'dummy'});
319319
group.isPlaceholder = true;
320320
return group;
321321
}

0 commit comments

Comments
 (0)