Skip to content

Commit

Permalink
refactor(component): className instead of _className (#438)
Browse files Browse the repository at this point in the history
* refactor(component): className instead of _className

* docs(readme): missing className

* fix(component): default to _className for backwards compat

* fix(component): missing ===
  • Loading branch information
redgeoff authored Aug 7, 2021
1 parent a5e4d99 commit f3eabc2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ import Form from 'mson/lib/form';
import { TextField, Email } from 'mson/lib/fields';

class MyAccount extends Form {
className = 'MyAccount';

create(props) {
super.create(props);
this.set({
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ it('should define className for all core components', () => {
component: name,
});

expect(c._className).toEqual(name);
expect(c.getClassName()).toEqual(name);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/prop-filler.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default class PropFiller {
let performDefaultClone = false;
let clonedObject = undefined;

if (item && item._className) {
if (item && (item._className || item.className)) {
// The item is a component, therefore we should not clone it. TODO: is there a better way to
// determine this?
clonedObject = item;
Expand Down
6 changes: 4 additions & 2 deletions src/component/base-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getNextKey = () => {
// - We attempted to require all access to all props via get() and set(), but this can cause
// infinite recursion, e.g. when a get() calls itself either directly or via some inherited logic.
export default class BaseComponent extends events.EventEmitter {
_className = 'Component';
className = 'Component';

_getBaseComponentSchema() {
return {
Expand Down Expand Up @@ -692,7 +692,9 @@ export default class BaseComponent extends events.EventEmitter {
// return this.constructor.name;
// }
//
return this._className;
// _className has been deprecated, use className instead.
//
return this._className === undefined ? this.className : this._className;
}

getParentClassName() {
Expand Down

0 comments on commit f3eabc2

Please sign in to comment.