Comments (1)
I don't really see what is wrong with this behaviour. On the contrary, exceptional behaviours make it harder to read someone else's code.
Look for instance at this piece of code I found in the React docs:
class ScrollingList extends React.Component {
constructor(props) {
super(props);
this.listRef = React.createRef();
}
getSnapshotBeforeUpdate(prevProps, prevState) {
// Are we adding new items to the list?
// Capture the scroll position so we can adjust scroll later.
if (prevProps.list.length < this.props.list.length) {
const list = this.listRef.current;
return list.scrollHeight - list.scrollTop;
}
return null;
}
componentDidUpdate(prevProps, prevState, snapshot) {
// If we have a snapshot value, we've just added new items.
// Adjust scroll so these new items don't push the old ones out of view.
// (snapshot here is the value returned from getSnapshotBeforeUpdate)
if (snapshot !== null) {
const list = this.listRef.current;
list.scrollTop = list.scrollHeight - snapshot;
}
}
render() {
return (
<div ref={this.listRef}>{/* ...contents... */}</div>
);
}
}
I know about render
and componentDidUpdate
but I have never heard of getSnapshotBeforeUpdate
. Is this a built-in react method? Without override
I need to break my flow and check it myself. What if this class had many custom methods as well. override
helps tell apart what's component lifecycle and what is not. (Many might be tempted to insert a fat multi-line comment to cut their file in sections like // ===== Lifecycle methods =====
for that purpose actually).
Granted render
is รผber-common and everyone knows about it, but the feature you are asking for opens the door to abuse for little apparent benefit.
I'll keep this open to debate but I am against it for now.
from tslint-override.
Related Issues (20)
- Separate rules for 'check-overrides' and 'explicit-overrides' HOT 2
- Confusing `exclude-interfaces` behaviour HOT 4
- Add support for changing the casing of the decorator for use in the fixer HOT 3
- Rule warns on overloads, and "fixes" overloads to make an *actual* error HOT 1
- Add an option to add a new line after jsDoc style fixes HOT 2
- Support of Project Reference HOT 1
- Replace tslint with typescript-eslint ? HOT 2
- Allow opting out variables HOT 1
- The override decorator is required on anonymous classes, even though they're invalid HOT 2
- Add a "@final" rule? HOT 1
- "new-line-after-decorators-and-tags" not working HOT 2
- Angular like syntax - @Override() HOT 2
- Improve fixers
- `window` cannot be found inside of Web Workers HOT 1
- Ignore methods with 'super' HOT 1
- Support decorator syntax
- Allow opting out of checking for interfaces HOT 4
- Add license
- npm install does not install rules directory HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tslint-override.