-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
[WIP] fix(Column): minResizeWidth
#535
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { A as emberArray, makeArray } from '@ember/array'; | ||
import { warn } from '@ember/debug'; | ||
import EmberObject, { computed } from '@ember/object'; | ||
import { isEmpty } from '@ember/utils'; | ||
import { guidFor } from '@ember/object/internals'; | ||
import { isEmpty, typeOf } from '@ember/utils'; | ||
import fixProto from 'ember-light-table/utils/fix-proto'; | ||
|
||
/** | ||
|
@@ -129,11 +130,37 @@ export default class Column extends EmberObject.extend({ | |
|
||
/** | ||
* The minimum width (in px) that this column can be resized to. | ||
* @property minResizeWidth | ||
* @property _minResizeWidth | ||
* @type {Number} | ||
* @default 0 | ||
* @private | ||
*/ | ||
_minResizeWidth: 0, | ||
|
||
/** | ||
* The minimum width that this column can be resized to. | ||
* @property minResizeWidth | ||
* @type {String} | ||
* @default '0px' | ||
*/ | ||
minResizeWidth: 0, | ||
minResizeWidth: computed({ | ||
get() { | ||
return this.get('_minResizeWidth'); | ||
}, | ||
set(key, value) { | ||
if (typeOf(value) === 'string') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typeof value === 'string' is a bit faster. The only advantage of Personally idc a lot about this scenario, but that just might be because this has never bitten me yet. Keep this line whatever you feel the most comfortable with. 😉 |
||
let [, quantity, units] = value.match(/(\d+)(px)?/) || []; | ||
if (units !== 'px') { | ||
warn('`value` attribute is interpreted as px regardless of provided units', { | ||
id: 'ember-light-table.classes.Column' | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const [, quantity, units] = value.match(/^\s*(\d+)([a-z]+|%)?\s*$/) || [];
assert(
`'minResizeWidth' can only interpret px unit values. You passed '${quantity}${unit}'.`,
isEmpty(units) || units === 'px'
); Being more restrictive here can help prevent subtle bugs. We should throw an assertion here, since |
||
} | ||
this.set('_minResizeWidth', Number(quantity)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return this.set('_minResizeWidth', Number(quantity));
This is why. When using the
By prepending |
||
} else { | ||
this.set('_minResizeWidth', value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return this.set('_minResizeWidth', value); Also, what about other non-string values? What if I pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @buschtoens The only concern I have about throwing assertions for I plan on making the suggested changes this upcoming week. |
||
} | ||
} | ||
}), | ||
|
||
/** | ||
* The parent column (or group) for this sub-column. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing dependent key
_minResizeWidth
.In practice this won't cause any problems yet, since
_minResizeWidth
is private API and exclusively managed by theminResizeWidth
computed property. However, that could possibly change in the future and the developer making that change then might not remember to add that key.