From 93d8fac342b69f1fc1a40907bc915d081ec6a0b1 Mon Sep 17 00:00:00 2001 From: Nicholas Yip Date: Sun, 30 Jan 2022 04:13:15 +0900 Subject: [PATCH 1/4] Minifier-friendly references to properties --- src/React.js | 59 +++++++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/src/React.js b/src/React.js index b445652..bd0203c 100644 --- a/src/React.js +++ b/src/React.js @@ -1,40 +1,14 @@ import React from "react"; function createClass(baseClass) { - function bindProperty(instance, prop, value) { - switch (prop) { - case "state": - case "render": - case "componentDidMount": - case "componentWillUnmount": - instance[prop] = value; - break; - - case "componentDidCatch": - case "componentWillUpdate": - case "shouldComponentUpdate": - case "getSnapshotBeforeUpdate": - instance[prop] = function (a, b) { return value(a)(b)(); }; - break; - - case "componentDidUpdate": - instance[prop] = function (a, b, c) { return value(a)(b)(c)(); }; - break; - - case "unsafeComponentWillMount": - instance["UNSAFE_componentWillMount"] = value; - break; - - case "unsafeComponentWillReceiveProps": - instance["UNSAFE_componentWillReceiveProps"] = function (a) { return value(a)(); }; - break; - - case "unsafeComponentWillUpdate": - instance["UNSAFE_componentWillUpdate"] = function (a, b) { return value(a)(b)(); }; - break; - - default: - throw new Error("[purescript-react] Not a component property: " + prop); + function curry2(f) { + return f === undefined ? f : function (a, b) { + return f(a)(b) + } + } + function curry3(f) { + return f === undefined ? f : function (a, b, c) { + return f(a)(b)(c) } } @@ -43,10 +17,19 @@ function createClass(baseClass) { var Constructor = function (props) { baseClass.call(this, props); var spec = ctrFn(this)(); - // eslint-disable-next-line guard-for-in - for (var k in spec) { - bindProperty(this, k, spec[k]); - } + + this.state = spec.state; + this.render = spec.render; + this.componentDidMount = spec.componentDidMount; + this.componentWillUnmount = spec.componentWillUnmount; + this.componentDidCatch = curry2(spec.componentDidCatch); + this.componentWillUpdate = curry2(spec.componentWillUpdate); + this.shouldComponentUpdate = curry2(spec.shouldComponentUpdate); + this.getSnapshotBeforeUpdate = curry2(spec.getSnapshotBeforeUpdate); + this.componentDidUpdate = curry3(spec.componentDidUpdate); + this.UNSAFE_componentWillMount = spec.unsafeComponentWillMount; + this.UNSAFE_componentWillReceiveProps = curry2(spec.unsafeComponentWillReceiveProps); + this.UNSAFE_componentWillUpdate = curry3(spec.unsafeComponentWillUpdate); }; Constructor.displayName = displayName; From 2e710dcac3551bc00cf37bae6cf6bcf15ade5372 Mon Sep 17 00:00:00 2001 From: Nicholas Yip Date: Sun, 30 Jan 2022 04:23:59 +0900 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bbf719..349f071 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Bugfixes: Other improvements: - Added `purs-tidy` formatter (#182 by @thomashoneyman) +- Minifier-friendly refereces to properties (#183 by @sd-yip) ## [v9.0.0](https://github.com/purescript-contrib/purescript-react/releases/tag/v9.0.0) - 2021-02-26 From 7946ba21b72b53f75baf0d78dccf6bc5eedcfa58 Mon Sep 17 00:00:00 2001 From: Nicholas Yip Date: Fri, 8 Apr 2022 15:41:16 +0900 Subject: [PATCH 3/4] Fix currying + invocation --- src/React.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/React.js b/src/React.js index bd0203c..8a20927 100644 --- a/src/React.js +++ b/src/React.js @@ -1,14 +1,19 @@ import React from "react"; function createClass(baseClass) { - function curry2(f) { + function invoke1(f) { + return f === undefined ? f : function (a) { + return f(a)() + } + } + function invoke2(f) { return f === undefined ? f : function (a, b) { - return f(a)(b) + return f(a)(b)() } } - function curry3(f) { + function invoke3(f) { return f === undefined ? f : function (a, b, c) { - return f(a)(b)(c) + return f(a)(b)(c)() } } @@ -22,14 +27,14 @@ function createClass(baseClass) { this.render = spec.render; this.componentDidMount = spec.componentDidMount; this.componentWillUnmount = spec.componentWillUnmount; - this.componentDidCatch = curry2(spec.componentDidCatch); - this.componentWillUpdate = curry2(spec.componentWillUpdate); - this.shouldComponentUpdate = curry2(spec.shouldComponentUpdate); - this.getSnapshotBeforeUpdate = curry2(spec.getSnapshotBeforeUpdate); - this.componentDidUpdate = curry3(spec.componentDidUpdate); + this.componentDidCatch = invoke2(spec.componentDidCatch); + this.componentWillUpdate = invoke2(spec.componentWillUpdate); + this.shouldComponentUpdate = invoke2(spec.shouldComponentUpdate); + this.getSnapshotBeforeUpdate = invoke2(spec.getSnapshotBeforeUpdate); + this.componentDidUpdate = invoke3(spec.componentDidUpdate); this.UNSAFE_componentWillMount = spec.unsafeComponentWillMount; - this.UNSAFE_componentWillReceiveProps = curry2(spec.unsafeComponentWillReceiveProps); - this.UNSAFE_componentWillUpdate = curry3(spec.unsafeComponentWillUpdate); + this.UNSAFE_componentWillReceiveProps = invoke1(spec.unsafeComponentWillReceiveProps); + this.UNSAFE_componentWillUpdate = invoke2(spec.unsafeComponentWillUpdate); }; Constructor.displayName = displayName; From 0e1943fcc6ef6b49d4ff444b7e10c16927f106e6 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 27 Apr 2022 15:00:00 -0500 Subject: [PATCH 4/4] Merge remote-tracking branch 'upstream/main' into minifier-friendly --- .github/workflows/ci.yml | 4 ++-- CHANGELOG.md | 16 +++++++++++++++- bower.json | 16 ++++++++-------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e16f413..fc54710 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,8 +50,8 @@ jobs: - name: Build the project run: npm run build -# - name: Run tests -# run: npm run test + - name: Run tests + run: npm run test - name: Check formatting run: purs-tidy check src test diff --git a/CHANGELOG.md b/CHANGELOG.md index 349f071..0368b5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,21 @@ Notable changes to this project are documented in this file. The format is based ## [Unreleased] +Breaking changes: + +New features: + +Bugfixes: + +Other improvements: + +## [v10.0.1](https://github.com/purescript-contrib/purescript-react/releases/tag/v10.0.1) - 2022-04-27 + +Other improvements: +- Minifier-friendly refereces to properties (#183 by @sd-yip) + +## [v10.0.0](https://github.com/purescript-contrib/purescript-react/releases/tag/v10.0.0) - 2022-04-27 + Breaking changes: - Migrate FFI to ES modules (#185 by @JordanMartinez) - Replaced polymorphic proxies with monomorphic `Proxy` (#185 by @JordanMartinez) @@ -14,7 +29,6 @@ Bugfixes: Other improvements: - Added `purs-tidy` formatter (#182 by @thomashoneyman) -- Minifier-friendly refereces to properties (#183 by @sd-yip) ## [v9.0.0](https://github.com/purescript-contrib/purescript-react/releases/tag/v9.0.0) - 2021-02-26 diff --git a/bower.json b/bower.json index eddfbf3..6709f7a 100644 --- a/bower.json +++ b/bower.json @@ -17,15 +17,15 @@ "url": "https://github.com/purescript-contrib/purescript-react.git" }, "dependencies": { - "purescript-effect": "master", - "purescript-exceptions": "master", - "purescript-maybe": "master", - "purescript-nullable": "main", - "purescript-prelude": "master", - "purescript-typelevel-prelude": "master", - "purescript-unsafe-coerce": "master" + "purescript-effect": "^4.0.0", + "purescript-exceptions": "^6.0.0", + "purescript-maybe": "^6.0.0", + "purescript-nullable": "^6.0.0", + "purescript-prelude": "^6.0.0", + "purescript-typelevel-prelude": "^7.0.0", + "purescript-unsafe-coerce": "^6.0.0" }, "devDependencies": { - "purescript-console": "master" + "purescript-console": "^6.0.0" } }