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

Commit f68a622

Browse files
authored
Merge pull request #189 from agile-ts/optimize-collection-rebuilds
Optimize collection rebuilds
2 parents 22a047e + ad56d39 commit f68a622

Some content is hidden

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

56 files changed

+1598
-387
lines changed

benchmark/benchmarks/react/1000fields/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ suite
8181
.add('Agile State', configTest(agileState))
8282
.add('Agile nested State', configTest(agileNestedState))
8383
.add('Pulse Collection', configTest(pulseCollection))
84-
// .add('Pulse State', configTest(pulseState))
85-
// .add('Pulse nested State', configTest(pulseNestedState))
84+
.add('Pulse State', configTest(pulseState))
85+
.add('Pulse nested State', configTest(pulseNestedState))
8686
.add('Hookstate', configTest(hookstate))
8787
.add('Jotai', configTest(jotai))
8888
.add('Mobx', configTest(mobx))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @ts-ignore
2+
import _ from 'lodash';
3+
4+
export function cloneDeep<T = any>(value: T): T {
5+
return _.cloneDeep(value);
6+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export function cloneDeep<T = any>(value: T): T {
2+
// Extra checking 'value == null' because 'typeof null === object'
3+
if (value == null || typeof value !== 'object') return value;
4+
5+
// Ignore everything that is no object or array but has the type of an object (e.g. classes)
6+
const valConstructorName = Object.getPrototypeOf(
7+
value
8+
).constructor.name.toLowerCase();
9+
if (valConstructorName !== 'object' && valConstructorName !== 'array')
10+
return value;
11+
12+
let temp;
13+
const newObject: any = Array.isArray(value) ? [] : {};
14+
for (const property in value) {
15+
temp = value[property];
16+
newObject[property] = cloneDeep(temp);
17+
}
18+
return newObject as T;
19+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function cloneDeep<T = any>(value: T): T {
2+
return JSON.parse(JSON.stringify(value));
3+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import Benchmark, { Suite } from 'benchmark';
2+
import {
3+
cycleLog,
4+
CycleResultInterface,
5+
endBenchmarkLog,
6+
getCycleResult,
7+
startBenchmarkLog,
8+
} from '../../benchmarkManager';
9+
10+
// Files to run the Benchmark on
11+
import * as lodash from './bench/lodash';
12+
import * as looper from './bench/looper';
13+
import * as stringify from './bench/stringify';
14+
15+
const toClone = { x1: true, x2: undefined };
16+
17+
// @ts-ignore
18+
// Benchmark.js requires an instance of itself globally
19+
window.Benchmark = Benchmark;
20+
21+
// Create new Benchmark Test Suite
22+
const suite = new Suite('clone deep');
23+
24+
const results: CycleResultInterface[] = [];
25+
26+
// Add Tests to the Benchmark Test Suite
27+
suite
28+
.add('Lodash', function () {
29+
lodash.cloneDeep(toClone);
30+
})
31+
.add('Looper', function () {
32+
looper.cloneDeep(toClone);
33+
})
34+
.add('Stringify', function () {
35+
stringify.cloneDeep(toClone);
36+
})
37+
38+
// Add Listener
39+
.on('start', function (this: any) {
40+
startBenchmarkLog(this.name);
41+
})
42+
.on('cycle', (event: any) => {
43+
const cycleResult = getCycleResult(event);
44+
cycleLog(cycleResult);
45+
results.push(cycleResult);
46+
})
47+
.on('complete', function (this: any) {
48+
endBenchmarkLog(this.name, results, this.filter('fastest').map('name'));
49+
50+
// @ts-ignore
51+
// Notify server that the Benchmark Test Suite has ended
52+
window.TEST.ended = true;
53+
})
54+
55+
// Run Benchmark Test Suite
56+
.run({ async: true });

benchmark/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"test:1000fields": "yarn test ./benchmarks/react/1000fields",
1313
"test:computed": "yarn test ./benchmarks/react/computed",
1414
"test:defineConfig": "yarn test ./benchmarks/typescript/defineConfig",
15+
"test:cloneDeep": "yarn test ./benchmarks/typescript/cloneDeep",
1516
"install:dev:agile": "yalc add @agile-ts/core @agile-ts/react & yarn install",
1617
"install:prod:agile": "yarn add @agile-ts/core @agile-ts/react & yarn install"
1718
},
@@ -21,8 +22,9 @@
2122
},
2223
"dependencies": {
2324
"@agile-ts/core": "file:.yalc/@agile-ts/core",
25+
"@agile-ts/logger": "file:.yalc/@agile-ts/logger",
2426
"@agile-ts/react": "file:.yalc/@agile-ts/react",
25-
"@hookstate/core": "^3.0.8",
27+
"@hookstate/core": "^3.0.11",
2628
"@pulsejs/core": "^4.0.0-beta.3",
2729
"@pulsejs/react": "^4.0.0-beta.3",
2830
"@reduxjs/toolkit": "^1.6.0",

benchmark/yarn.lock

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44

55
"@agile-ts/core@file:.yalc/@agile-ts/core":
6-
version "0.2.0-alpha.3"
6+
version "0.2.0-alpha.5"
7+
dependencies:
8+
"@agile-ts/utils" "^0.0.7"
9+
10+
"@agile-ts/logger@file:.yalc/@agile-ts/logger":
11+
version "0.0.7"
712
dependencies:
813
"@agile-ts/utils" "^0.0.7"
914

@@ -22,10 +27,10 @@
2227
dependencies:
2328
regenerator-runtime "^0.13.4"
2429

25-
"@hookstate/core@^3.0.8":
26-
version "3.0.8"
27-
resolved "https://registry.yarnpkg.com/@hookstate/core/-/core-3.0.8.tgz#d6838153d6d43c2f35cfca475c31248192564e62"
28-
integrity sha512-blQagGIVIbNoUiNCRrvaXqFmUe7WGMY35ok/LENfl2pcIsLBjkreYIZiaSFi83tkycwq7ZOmcQz/R1nvLKhH8w==
30+
"@hookstate/core@^3.0.11":
31+
version "3.0.11"
32+
resolved "https://registry.yarnpkg.com/@hookstate/core/-/core-3.0.11.tgz#515f2748b3741f3d7e90cbc1acff8d6ac84e5494"
33+
integrity sha512-cbI711aFWX4d8+xkLxikmLnR+f55ePHrBMWFA4gTLEoCa1+Cg0pfNw7h7zSodYMeYt8Y5A5TVSh7a5p8lBC89A==
2934

3035
"@pulsejs/core@^4.0.0-beta.3":
3136
version "4.0.0-beta.3"

examples/react/develop/fields/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SKIP_PREFLIGHT_CHECK=true
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Getting Started with Create React App
2+
3+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4+
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
### `yarn start`
10+
11+
Runs the app in the development mode.\
12+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13+
14+
The page will reload if you make edits.\
15+
You will also see any lint errors in the console.
16+
17+
### `yarn test`
18+
19+
Launches the test runner in the interactive watch mode.\
20+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21+
22+
### `yarn build`
23+
24+
Builds the app for production to the `build` folder.\
25+
It correctly bundles React in production mode and optimizes the build for the best performance.
26+
27+
The build is minified and the filenames include the hashes.\
28+
Your app is ready to be deployed!
29+
30+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31+
32+
### `yarn eject`
33+
34+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35+
36+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37+
38+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39+
40+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41+
42+
## Learn More
43+
44+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45+
46+
To learn React, check out the [React documentation](https://reactjs.org/).
47+
48+
### Code Splitting
49+
50+
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51+
52+
### Analyzing the Bundle Size
53+
54+
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55+
56+
### Making a Progressive Web App
57+
58+
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59+
60+
### Advanced Configuration
61+
62+
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63+
64+
### Deployment
65+
66+
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67+
68+
### `yarn build` fails to minify
69+
70+
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

0 commit comments

Comments
 (0)