From 65744f3984c379bc1bbca26942aca477552d0298 Mon Sep 17 00:00:00 2001 From: Derek Benson Date: Mon, 30 Sep 2019 14:25:19 -0400 Subject: [PATCH 1/3] define the name property of function return by createAction currently all functions returned by createAction are named res, which is fine but isn't helpful. I'd like to define the name of the function to be the actionName. --- src/core/action.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/action.ts b/src/core/action.ts index ddff349b3..cd8bd265b 100644 --- a/src/core/action.ts +++ b/src/core/action.ts @@ -27,6 +27,7 @@ export function createAction(actionName: string, fn: Function, ref?: Object): Fu return executeAction(actionName, fn, ref || this, arguments) } ;(res as any).isMobxAction = true + Object.defineProperty(res, "name", {value: actionName}); return res as any } From 501da50f79e144486e5b6193a9e8fb3b1c424159 Mon Sep 17 00:00:00 2001 From: Derek Benson Date: Wed, 2 Oct 2019 16:04:59 -0400 Subject: [PATCH 2/3] restrict change to development mode and when name is configurable --- src/core/action.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/action.ts b/src/core/action.ts index cd8bd265b..0c19f0883 100644 --- a/src/core/action.ts +++ b/src/core/action.ts @@ -27,7 +27,9 @@ export function createAction(actionName: string, fn: Function, ref?: Object): Fu return executeAction(actionName, fn, ref || this, arguments) } ;(res as any).isMobxAction = true - Object.defineProperty(res, "name", {value: actionName}); + if (process.env.NODE_ENV !== "production" && Object.getOwnPropertyDescriptor(res, "name").configurable) { + Object.defineProperty(res, "name", {value: actionName}); + } return res as any } From 4eb0ae475b9f4cebd337faea83a80fbb122930e0 Mon Sep 17 00:00:00 2001 From: Derek Benson Date: Wed, 2 Oct 2019 16:10:12 -0400 Subject: [PATCH 3/3] check to make sure descriptor exists before using it --- src/core/action.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/action.ts b/src/core/action.ts index 0c19f0883..ec59e7ecc 100644 --- a/src/core/action.ts +++ b/src/core/action.ts @@ -27,8 +27,11 @@ export function createAction(actionName: string, fn: Function, ref?: Object): Fu return executeAction(actionName, fn, ref || this, arguments) } ;(res as any).isMobxAction = true - if (process.env.NODE_ENV !== "production" && Object.getOwnPropertyDescriptor(res, "name").configurable) { - Object.defineProperty(res, "name", {value: actionName}); + if (process.env.NODE_ENV !== "production") { + const descriptor = Object.getOwnPropertyDescriptor(res, "name"); + if (descriptor && descriptor.configurable) { + Object.defineProperty(res, "name", {value: actionName}); + } } return res as any }