Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobx6 - Add action name in prod too #2343

Merged
merged 5 commits into from
Apr 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/**/package.json
website/**/*
dist/
docs/assets/
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# UNPUBLISHED (keep this here and add unpublished changes)

- Add error when computed value declared for unspecified getter [#1867](https://github.com/mobxjs/mobx/issues/1867) by [@berrunder](https://github.com/berrunder)
- Don't omit action name in production [#2263](https://github.com/mobxjs/mobx/issues/2263) by [@elektronik2k5](https://github.com/elektronik2k5)
- Update readme to reflect correct scripts by [@elektronik2k5](https://github.com/elektronik2k5)
- `prettier` related tweaks by [@elektronik2k5](https://github.com/elektronik2k5)

# 5.15.4 / 4.15.4

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ And finally, kudos to all the people that believed in, tried, validated and even

- Feel free to send small pull requests. Please discuss new features or big changes in a GitHub issue first.
- Use `yarn test` to run the basic test suite.
- Use `yarn test:ci` for the test suite with coverage.
- and `yarn test:performance` for the performance tests.
- Use `yarn test:coverage` for the test suite with coverage.
- and `yarn perf` for the performance tests.
- Please note that if you want to backport a feature / fix to MobX 4 a second PR needs to be opened to the mobx4-master branch.

## Online one-click setup for contributing
Expand Down
4 changes: 3 additions & 1 deletion docs/best/pitfalls.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ export const MyComponent = observer(props => <div>hi</div>)
myComponent.displayName = "MyComponent"

// 2 (MobX infers component name from function name)
export const MyComponent = observer(function MyComponent(props) { return <div>hi</div> })
export const MyComponent = observer(function MyComponent(props) {
return <div>hi</div>
})

// 3 (transpiler will infer component name from variable name)
const _MyComponent = props => <div>hi</div>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
"test": "jest",
"lint": "eslint src/**/*.ts",
"watch": "jest --watch",
"perf": "yarn test:performance proxy && yarn test:performance legacy",
"perf": "yarn build && yarn test:performance proxy && yarn test:performance legacy",
"test:mixed-versions": "jest --testRegex mixed-versions",
"test:check": "yarn test:types && yarn lint",
"test:types": "yarn tsc --noEmit && yarn test:flow",
"test:flow": "node_modules/.bin/flow check",
"test:flow": "flow check",
"test:coverage": "yarn test -i --coverage",
"test:performance": "PERSIST=true time node --expose-gc test/perf/index.js",
"test:size": "yarn build && yarn import-size --report . observable computed autorun action enableDecorators",
"test:codemod": "yarn jest --testRegex 'codemod/.*spec' codemod/undecorate.spec.ts",
"prettier": "prettier \"**/*.js\" \"**/*.ts\" \"docs/**/*.md\"",
"prettier": "prettier --write '**/*.{js,ts,md}'",
"prebuild": "rimraf lib",
"build": "tsdx build --name mobx --format esm,cjs,umd",
"postbuild": "cp flow-typed/mobx.js dist/index.js.flow",
Expand Down
15 changes: 6 additions & 9 deletions src/core/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,21 @@ import { allowStateReadsStart, allowStateReadsEnd } from "./derivation"
let currentActionId = 0
let nextActionId = 1
const functionNameDescriptor = Object.getOwnPropertyDescriptor(() => {}, "name")
const isFunctionNameConfigurable = functionNameDescriptor && functionNameDescriptor.configurable
const isFunctionNameConfigurable = functionNameDescriptor?.configurable ?? false

export function createAction(actionName: string, fn: Function, ref?: Object): Function {
if (__DEV__) {
invariant(typeof fn === "function", "`action` can only be invoked on functions")
if (typeof actionName !== "string" || !actionName)
fail(`actions should have valid names, got: '${actionName}'`)
}
const res = function() {
function res() {
return executeAction(actionName, fn, ref || this, arguments)
}
;(res as any).isMobxAction = true
if (__DEV__) {
if (isFunctionNameConfigurable) {
Object.defineProperty(res, "name", { value: actionName })
}
}
return res as any
return Object.defineProperties(res, {
...(isFunctionNameConfigurable && { name: { value: actionName } }),
isMobxAction: { value: true }
})
}

export function executeAction(actionName: string, fn: Function, scope?: any, args?: IArguments) {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/eq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ function eq(a: any, b: any, depth: number, aStack?: any[], bStack?: any[]) {
typeof bCtor === "function" &&
bCtor instanceof bCtor
) &&
"constructor" in a && "constructor" in b
"constructor" in a &&
"constructor" in b
) {
return false
}
Expand Down