$30 off During Our Annual Pro Sale. View Details »

Dealing With Dependancies in JavaScript

Dealing With Dependancies in JavaScript

Radoslav Stankov

October 27, 2019
Tweet

More Decks by Radoslav Stankov

Other Decks in Technology

Transcript

  1. Dealing with dependencies
    in
    JavaScript
    (like a champ !)
    Radoslav Stankov 31/10/2019

    View Slide

  2. View Slide

  3. Radoslav Stankov
    @rstankov

    http://rstankov.com

    http://github.com/rstankov

    View Slide

  4. View Slide

  5. https://speakerdeck.com/rstankov

    View Slide

  6. View Slide

  7. View Slide

  8. open ./node_modules

    View Slide

  9. View Slide

  10. View Slide

  11. " JavaScript Fatigue

    View Slide

  12. View Slide

  13. View Slide

  14. View Slide

  15. View Slide

  16. What framework to use?
    How to manage state?
    How to fetch data?
    Which router to use?
    Which calendar component to use?
    Which chart component to use?

    ...
    #

    View Slide

  17. Agenda

    View Slide

  18. $ Dependency types
    % Picking dependencies
    & Handling dependencies

    View Slide

  19. Dependency types

    View Slide

  20. Medium
    easy

    to change
    Big
    Medium
    Small
    Medium
    Small
    Small
    Small
    Small Small
    hard
    to change
    simple complex
    * totally unscientific chart '

    View Slide

  21. Medium
    easy

    to change
    Big
    Medium
    Small
    Medium
    Small
    Small
    Small
    Small Small
    hard
    to change
    simple complex
    * totally unscientific chart '

    View Slide

  22. What framework to use?
    How to manage state?
    How to fetch data?
    Which router to use?
    Which calendar component to use?
    Which chart component to use?

    ...
    #

    View Slide

  23. What framework to use?
    How to manage state?
    How to fetch data?
    Which router to use?
    Which calendar component to use?
    Which chart component to use?

    ...
    #

    View Slide

  24. What ecosystem to choose?
    How to manage state?
    How to fetch data?
    Which router to use?
    Which calendar component use?
    Which chart component use?

    ...
    #

    View Slide

  25. What ecosystem to choose?
    How to manage state?
    How to fetch data?
    Which router to use?
    Which calendar component use?
    Which chart component use?

    ...
    #

    View Slide

  26. View Slide

  27. History of JS Ecosystem

    View Slide

  28. History of JS Ecosystem
    2005

    View Slide

  29. History of JS Ecosystem
    2005 2006

    View Slide

  30. History of JS Ecosystem
    2005 2010
    2006

    View Slide

  31. History of JS Ecosystem
    2005 2010
    2006

    View Slide

  32. History of JS Ecosystem
    2005 2013
    2010
    2006

    View Slide

  33. History of JS Ecosystem
    2005 2019
    2013
    2010
    2006

    View Slide

  34. View Slide

  35. View Slide

  36. View Slide

  37. What ecosystem to choose?
    How to manage state?
    How to fetch data?
    Which router to use?
    Which calendar component use?
    Which chart component use?

    ...
    #

    View Slide

  38. What ecosystem to choose?
    How to manage state?
    How to fetch data?
    Which router to use?
    Which calendar component use?
    Which chart component use?

    ...
    #

    View Slide

  39. Medium
    easy

    to change
    Big
    Medium
    Small
    Medium
    Small
    Small
    Small
    Small Small
    hard
    to change
    simple complex
    * totally unscientific chart '

    View Slide

  40. View Slide

  41. View Slide

  42. History of React Ecosystem
    2013 2019

    View Slide

  43. History of React Ecosystem
    2013 2019
    2014

    View Slide

  44. History of React Ecosystem
    2013 2019
    2014 2015

    View Slide

  45. History of React Ecosystem
    2013 2019
    2014 2015

    View Slide

  46. History of React Ecosystem
    2013 2019
    2014 2015 2016

    View Slide

  47. History of React Ecosystem
    2013 2019
    2014 2015 2016
    Concepts

    View Slide

  48. History of React Ecosystem
    2013 2019
    2014 2015 2016
    Libraries

    View Slide

  49. History of React Ecosystem
    2013 2019
    2014 2015 2016

    View Slide

  50. View Slide

  51. View Slide

  52. What ecosystem to choose?
    How to manage state?
    How to fetch data?
    Which router to use?
    Which calendar component use?
    Which chart component use?

    ...
    #

    View Slide

  53. Medium
    easy

    to change
    Big
    Medium
    Small
    Medium
    Small
    Small
    Small
    Small Small
    hard
    to change
    simple complex
    * totally unscientific chart '

    View Slide

  54. Picking Dependencies

    View Slide

  55. ⏹ Do we really need it?
    ⏹ Can something we already have do the task we are searching for?
    ⏹ Can we implement this ourselves?
    ⏹ Is this properly maintained?
    ⏹ Is it well documented?
    ⏹ When was the last version?
    ⏹ When was the last commit?
    ⏹ How often does it get a new version?
    ⏹ Does it have CHANGELOG?
    ⏹ Were there breaking changes recently?
    ⏹ Does it have security issues past or present?
    ⏹ How many dependencies does it come from?
    ⏹ What the dependency size?
    ⏹ What is its license?
    ⏹ Do you use this in any other project?
    ✅ Questions

    View Slide

  56. https://www.npmjs.com/package/lodash

    View Slide

  57. https://www.npmjs.com/package/lodash

    View Slide

  58. https://www.npmjs.com/package/draft-js

    View Slide

  59. https://github.com/facebook/draft-js

    View Slide

  60. https://github.com/facebook/draft-js/issues

    View Slide

  61. http://npm.broofa.com/?q=draft-js

    View Slide

  62. https://bundlephobia.com/[email protected]

    View Slide

  63. View Slide

  64. Handling dependencies

    View Slide

  65. Who is developer worst enemy?

    View Slide

  66. * The designer
    Who is developer worst enemy?

    View Slide

  67. * The designer
    + The QA
    Who is developer worst enemy?

    View Slide

  68. * The designer
    + The QA
    , The sys admin
    Who is developer worst enemy?

    View Slide

  69. * The designer
    + The QA
    , The sys admin
    - The project owner
    Who is developer worst enemy?

    View Slide

  70. * The designer
    + The QA
    , The sys admin
    - The project owner
    . Santa
    Who is developer worst enemy?

    View Slide

  71. * The designer
    + The QA
    , The sys admin
    - The project owner
    . Santa
    / Code coupling
    Who is developer worst enemy?

    View Slide

  72. * The designer
    + The QA
    , The sys admin
    - The project owner
    . Santa
    / Code coupling
    Who is developer worst enemy?

    View Slide

  73. / Code coupling

    View Slide

  74. View Slide

  75. View Slide

  76. // pages/Home/index.js
    import * as React from 'react';
    import { Jumbotron } from 'react-bootstrap';
    import { Link } from 'react-router';
    import moment from 'moment';
    import styles from './styles.css';
    import globalStyles from 'styles/global.css';
    import classNames from 'classNames';
    import FancyTime from 'fancy-time'
    export default class Page extends React.Component {
    state = {
    time: new Date(),
    };
    componentDidMount() {
    this.interval = setInterval(this.updateTime, 1000);
    }
    componentWillUnmount() {
    clearInterval(this.interval);
    this.interval = null;
    }
    updateTime = () => {
    this.setState({ time: new Date() });
    }
    render() {
    const { time } = this.state.time;
    return (

    Conference

    View Slide

  77. export default class Page extends React.Component {
    state = {
    time: new Date(),
    };
    componentDidMount() {
    this.interval = setInterval(this.updateTime, 1000);
    }
    componentWillUnmount() {
    clearInterval(this.interval);
    this.interval = null;
    }
    updateTime = () => {
    this.setState({ time: new Date() });
    }
    render() {
    const { time } = this.state.time;
    return (

    Conference

    className={className(styles.clock, globalStyles.time)}
    datetime={moment(time).format()}>
    {moment(time).format('HH:mm')}

    Schedule
    Venue


    );
    }
    }

    View Slide

  78. Reasons for change

    View Slide

  79. Component
    Dependency Dependency Dependency

    View Slide

  80. Component
    Dependency Dependency Dependency
    Component Component
    Dependency Dependency

    View Slide

  81. Component
    Component Component
    Dependency
    nent Comp
    Dependency
    Dependency
    Dependency Dependency Dependency Dependency Dep
    cy

    View Slide

  82. Control changes

    View Slide

  83. Component
    Dependency Dependency

    View Slide

  84. Component
    Dependency Dependency
    Component

    View Slide

  85. Component
    Dependency Dependency
    Component
    Component Component

    View Slide

  86. Time
    Moment FancyTime
    Page
    Page Page

    View Slide

  87. export default class Page extends React.Component {
    state = {
    time: new Date(),
    };
    componentDidMount() {
    this.interval = setInterval(this.updateTime, 1000);
    }
    componentWillUnmount() {
    clearInterval(this.interval);
    this.interval = null;
    }
    updateTime = () => {
    this.setState({ time: new Date() });
    }
    render() {
    const { time } = this.state.time;
    return (

    Conference

    className={className(styles.clock, globalStyles.time)}
    datetime={moment(time).format()}>
    {moment(time).format('HH:mm')}

    Schedule
    Venue


    );
    }
    }

    View Slide

  88. export default class Page extends React.Component {
    state = {
    time: new Date(),
    };
    componentDidMount() {
    this.interval = setInterval(this.updateTime, 1000);
    }
    componentWillUnmount() {
    clearInterval(this.interval);
    this.interval = null;
    }
    updateTime = () => {
    this.setState({ time: new Date() });
    }
    render() {
    const { time } = this.state.time;
    return (

    Conference


    Schedule
    Venue


    );
    }
    }

    View Slide

  89. // components/Time/index.js
    import * as React from 'react';
    import classNames from 'classNames';
    import styles from './styles.css';
    import moment from 'moment';
    import FancyTime from 'fancy-time';
    export default function Time({ className, time }) {
    return (
    className={className(styles.time, className)}
    datetime={moment(time).format()}>
    {moment(time).format('HH:mm')}

    );
    }

    View Slide

  90. Time
    Moment FancyTime
    Page
    Page Page

    View Slide

  91. Time
    Utils FancyTime
    Page
    Page Page
    Moment

    View Slide

  92. // components/Time/index.js
    import * as React from 'react';
    import classNames from 'classNames';
    import styles from './styles.css';
    import { formatTime } from './utils';
    import FancyTime from 'fancy-time';
    export default function Time({ className, time }) {
    return (
    className={className(styles.time, className)}
    datetime={formatTime('full'}>
    {formatTime('clock')}

    );
    }
    // components/Time/utils.js
    import moment from 'moment';
    const FORMATS = {
    'full': null,
    'clock': 'HH:mm',
    };
    export function formatTime(time, kind) {
    const format = FORMATS[kind]
    return moment(time).format(format);
    }

    View Slide

  93. // pages/Home/index.js
    import * as React from 'react';
    import { Jumbotron } from 'react-bootstrap';
    import { Link } from 'react-router';
    import styles from './styles.css';
    import globalStyles from 'styles/global.css';
    import classNames from 'classNames';

    import Time from 'components/Time';
    export default class Page extends React.Component {
    state = {
    time: new Date(),
    };
    componentDidMount() {
    this.interval = setInterval(this.updateTime, 1000);
    }
    componentWillUnmount() {
    clearInterval(this.interval);
    this.interval = null;
    }
    updateTime = () => {
    this.setState({ time: new Date() });
    }
    render() {
    const { time } = this.state.time;
    return (

    Conference

    View Slide

  94. // pages/Home/index.js
    import * as React from 'react';
    import { Jumbotron } from 'react-bootstrap';
    import { Link } from 'react-router';
    import styles from './styles.css';
    import globalStyles from 'styles/global.css';
    import classNames from 'classNames';
    import Time from 'components/Time';
    import Clock from 'components/Clock';
    export default class Page extends React.Component {
    render() {
    return (

    Conference


    {(time) => }

    Schedule
    Venue


    );
    }
    }

    View Slide

  95. // pages/Home/index.js
    import * as React from 'react';
    import { Jumbotron } from 'react-bootstrap';
    import { Link } from 'react-router';
    import styles from './styles.css';
    import globalStyles from 'styles/global.css';
    import classNames from 'classNames';
    import Time from 'components/Time';
    import Clock from 'components/Clock';
    export default class Page extends React.Component {
    render() {
    return (

    Conference


    {(time) => }

    Schedule
    Venue


    );
    }
    }

    View Slide

  96. // pages/Home/index.js
    import * as React from 'react';
    import { Link } from 'react-router';
    import Time from 'components/Time';
    import Clock from 'components/Clock';
    import Jumbotron from 'components/Jumbotron';
    export default function Page() {
    return (


    {(time) => }

    Schedule
    Venue

    );
    }

    View Slide

  97. // paths.js
    export default {
    schedule() {
    return '/schedule';
    },
    venue() {
    return '/venue';
    }
    };

    View Slide

  98. // pages/Home/index.js
    import * as React from 'react';
    import { Link } from 'react-router';
    import paths from 'paths';
    import Time from 'components/Time';
    import Clock from 'components/Clock';
    import Jumbotron from 'components/Jumbotron';
    export default function Page() {
    return (


    {(time) => }

    Schedule
    Venue

    );
    }

    View Slide

  99. // pages/Home/index.js
    import * as React from 'react';
    import { Link } from 'react-router';
    import paths from 'paths';
    import Time from 'components/Time';
    import Clock from 'components/Clock';
    import Jumbotron from 'components/Jumbotron';
    export default function Page() {
    return (


    {(time) => }

    Schedule
    Venue

    );
    }

    View Slide

  100. // components/Link/index.js
    import { Link } from 'react-router';
    export default function Link({ to, className, children }) {
    return (
    {children}
    );
    }

    View Slide

  101. // components/Link/index.js
    import { Link } from 'found';
    export default function Link({ to, className, children }) {
    return (
    {children}
    );
    }

    View Slide

  102. View Slide

  103. View Slide

  104. View Slide

  105. Thanks 0

    View Slide

  106. https://speakerdeck.com/rstankov

    View Slide