Props
Cons
The idea of this tech talk to have a short and interactive tech talk. This tech talk will revolve around two things.
Presenter: Muhammad Tahir Hassan
Designation: Senior Software Engineer
Presenter: Adeel Akram
Designation: Software Engineering Lead
const inprogress = {};
myFunction (param) {
const uniqueKey = param.value;
if (inprogress[uniqueKey]) {
return inprogress[uniqueKey];
}
inprogress[uniqueKey] = new Promise((resolve, reject) => {
// implementation
//InEnd
delete inprogress[uniqueKey];
});
return inprogress[uniqueKey];
}
Presenter: Saad Abbasi
Designation: Software Engineer
{
students: [...]
}
{
marketing: [...],
engineering: [...],
design: [...],
}
component
action
normalization
data
store
❌
API Server
{
students: [...]
}
component
action
data
store
API Server
{
students: [...]
}
data
getEngineers()
selectors
getMarketeers()
getDesigners()
hof-connect()
getEngineers()
selectors
getMarketeers()
getDesigners()
hof-connect()
isn't it???
to the rescue
const students = store.students;
export const engineerSelector = createSelector(
students,
() => students.filter((std) => std.degree === 'engineering');
)
export const designerSelector = createSelector(
students,
() => students.filter((std) => std.degree === 'art and design');
)
export const marketingSelector = createSelector(
students,
() => students.filter((std) => std.degree === 'marketing');
)
const students = store.students;
export const getStudentById = (id = '') => {
return createSelector(
students,
(students = []) => students.find((std) => std.id === id);
);
};
memoization dead 💀
possibly mem-leak ☢️
class ABC extends React.Component {
componentWillReceiveProps(prev, next){
if (prev.students !== next.students) {
const studentId = router.params.id;
this.setState({
student: this.props.students.find(std => std.id === id);
});
}
}
render(){
const data = this.state.student;
return (
<StudentBio data={data}/>
);
}
}
export default connect(
(state) => ({students: state.students})
)(ABC);
O(n)
every single time 🙄
to the rescue
{
students: [...]
}
component
not objects
store
{
students: [
{101: {...}},
{102: {...}},
{103: {...}},
]}
entities
getEngineers()
selectors
getMarketeers()
getDesigners()
hof-connect()
API Server
const students = store.students;
export const engineerSelector = createSelector(
students,
(students) => Object.values(students).filter(
(std) => std.degree === 'engineering');
)
export const designerSelector = createSelector(
students,
(students) => Object.values(students).filter(
(std) => std.degree === 'art and design');
)
export const marketingSelector = createSelector(
students,
(students) => Object.values(students).filter(
(std) => std.degree === 'marketing');
)
as per entities
class ABC extends React.Component {
componentWillReceiveProps(prev, next){
if (prev.students !== next.students) {
const studentId = router.params.id;
this.setState({
student: this.props.students[studentId];
});
}
}
render(){
const data = this.state.student;
return (
<StudentBio data={data}/>
);
}
}
export default connect(
(state) => ({students: state.students})
)(ABC);
O(1)
holy cow 😃😃😃
🎇
any questions?
Presenter: Junaid Ahmed
Designation: Software Engineer
Presenter: Ahsan
Designation: Software Engineer