Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

React + Flux (Alt)

7.387 Aufrufe

Veröffentlicht am

Como se encontra a web atualmente e suas necessidades. Exemplos de React e Flux com ES6.

Veröffentlicht in: Technologie
  • accessibility Books Library allowing access to top content, including thousands of title from favorite author, plus the ability to read or download a huge selection of books for your pc or smartphone within minutes ,Download or read Ebooks here ... ......................................................................................................................... Download FULL PDF EBOOK here { http://bit.ly/2m6jJ5M }
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • DOWNLOAD THI5 BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • DOWNLOAD THI5 BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier

React + Flux (Alt)

  1. 1. React? Já ouvi falar
  2. 2. Temas abordados 1. Problemas atuais da web 2. Onde a web está 3. Futuro? 4. Como o desenvolvimento é hoje 5. React 6. Flux
  3. 3. Cezar Luiz Programador Front-End JavaScript <3 Trabalha na Snowman Labs 23 anos
  4. 4. Web nos dias de hoje
  5. 5. Muita demanda de informação
  6. 6. Muita gente conectada
  7. 7. performance !important
  8. 8. Tempo de resposta deve ser cada vez menor
  9. 9. Onde a web está presente
  10. 10. Falando sobre front-end
  11. 11. Muito do que se faz hoje MVC Mineração de DOM - getElementById, etc Adiciona classe, retira classe Problemas de compatibilidade Dificuldade em escalar e aceitar grande quantidade de dados
  12. 12. Problemas com MVC
  13. 13. “MVC got really complicated really quickly”
  14. 14. !
  15. 15. Virtual DOM React abstracts away the DOM from you, giving a simpler programming model and better performance. React can also render on the server using Node, and it can power native apps using React Native.
  16. 16. Data Flow React implements one-way reactive data flow which reduces boilerplate and is easier to reason about than traditional data binding.
  17. 17. !framework
  18. 18. Por que não pensar mais na sua aplicação, na lógica, do que ficar se preocupando com o “DOM”?
  19. 19. import React from 'react'; import ReactDOM from 'react-dom'; class HelloWorld extends React.Component { render() { return <div>Hello World!</div> } } ReactDOM.render(<HelloWorld />, mountNode); JSX
  20. 20. import React from 'react'; import ReactDOM from 'react-dom'; class HelloWorld extends React.Component { render() { return React.createElement( "div", null, "Hello World" ); } } ReactDOM.render(React.createElement(HelloWorld), mountNode); JS compilado
  21. 21. state e PROPS Onde gerenciamos os dados da nossa aplicação
  22. 22. import MailHeader from './MailHeaderComponent'; import MailButtons from './MailButtonsComponent'; import MailsTable from './MailTablesComponent'; class Mails extends React.Component { render() { return ( <div className="mails-container"> <MailHeader /> <MailButtons /> <MailsTable /> </div> ); } }
  23. 23. import HeaderTitle from './header/HeaderTitleComponent'; import HeaderSearch from './header/HeaderSearchComponent'; import Profile from './ProfileComponent'; class MailHeader extends React.Component { render() { return ( <header className="mail-header"> <HeaderTitle title="Inbox" /> <HeaderSearch placeholder="Search..." /> <Profile user={user} /> </header> ); } }
  24. 24. import MailRow from './MailRowComponent'; class MailTable extends React.Component { constructor(props) { super(props); this.state = { loading: false, mails: [] }; } componentDidMount() { this.setState({ loading: true }); $.ajax({ url: `${host}/mails` }) .done((response) => { this.setState({ mails: response.results }); }) .complete(() => { this.setState({ loading: false }); }); } render() { if (this.state.loading) { return <p>Carregando emails...</p> } if (!this.state.mails.length) { return <p>Nenhum email por enquanto.</p> } return ( <table className="mails-table"> <thead>...</thead> <tbody> {this.state.mails.map((mail) => { return <MailRow mail={mail} /> })} </tbody> </table> ); } }
  25. 25. import MailRow from './MailRowComponent'; import $ from 'jquery'; class MailTable extends React.Component { constructor(props) { super(props); this.state = { loading: false, mails: [] }; } ... }
  26. 26. import MailRow from './MailRowComponent'; import $ from 'jquery'; class MailTable extends React.Component { ... componentDidMount() { this.setState({ loading: true }); $.ajax({ url: `${host}/mails` }) .done((response) => { this.setState({ mails: response.results }); }) .complete(() => { this.setState({ loading: false }); }); } ... }
  27. 27. import MailRow from './MailRowComponent'; class MailTable extends React.Component { ... render() { if (this.state.loading) { return <p>Carregando emails...</p> } if (!this.state.mails.length) { return <p>Nenhum email por enquanto.</p> } return ( <table className="mails-table"> <thead>...</thead> <tbody> {this.state.mails.map((mail) => { return <MailRow mail={mail} /> })} </tbody> </table> ); } }
  28. 28. class MailRow extends React.Component { changeCheck() { let checkbox = this.refs.checkbox; let dom = React.findDOMNode(checkbox); // Não é tão necessário let { value, name, type } = checkbox; ... } render() { return ( <tr> <td> <input onChange={this.changeCheck.bind(this)} type="checkbox" name="checkMail" ref="checkbox" /> </td> <td>{this.props.name}</td> <td>{this.props.resume}</td> <td>{this.props.date}</td> </tr> ); } }
  29. 29. c o m p o n e n t i z a ç ã o
  30. 30. ciclo de vida
  31. 31. 3 partes principais Mounting - Um componente irá ser inserido no DOM. Updating - Um componente está a ser re-renderizado para determinar se o DOM deverá ser atualizado. (Virtual DOM) Unmounting - Um componente está sendo removido do DOM. Além disso, o React fornece métodos de ciclos de vida para você interceptar esse processo. Métodos do tipo “will”.
  32. 32. Mounting - 3 métodos getInitialState - Chamado antes de um componente ser montado. Componentes que usam state devem implementar isso para retornar dados iniciais. componentWillMount - Chamado imediatamente antes de ocorrer a montagem. componentDidMount - Chamado imediatamente depois de ocorrer a montagem. Se precisar alterar o DOM, deve vir aqui.
  33. 33. Updating - 4 métodos componentWillReceiveProps(object nextProps) - Chamado quando um componente recebe novas propriedades. shouldComponentUpdate(object nextProps, object nextState) Deve retornar um boolean se o componente deverá ser atualizado ou não. componentWillUpdate(object nextProps, object nextState) Chamado imediatamente antes de uma atualização acontecer. Não pode chamar this.setState aqui. componentDidUpdate(object prevProps, object prevState) Chamado imediatamente depois da atualização acontecer.
  34. 34. Unmounting - 1 método componentWillUnmount - Chamado imediatamente antes de um componente ser desmontado e destruído. Limpezas devem ser feitas aqui.
  35. 35. state props refs render ciclos de vida componentização JSX e JS compilado UI complexas event system (onClick onChange...) ajax isso é React
  36. 36. E o tal do flux?
  37. 37. !framework
  38. 38. Arquitetura de aplicação para construir interfaces
  39. 39. “simplificar”
  40. 40. exemplos com altjs
  41. 41. // dispatcher.js import alt from 'alt'; let alt = new Alt(); export default alt;
  42. 42. // actions/MailActions.js import alt from '../dispatcher'; import $ from 'jquery'; class MailActions { getMails() { $.ajax({ url: `${host}/mails` }) .done((res) => { this.actions.getMailsSuccess(res); }) .fail(() => { this.actions.getMailsFail(); }); return true; } getMailsSuccess(res) { return res; } getMailsFail() { // Envia uma notificação de erro para o usuário na tela return false; } } export default alt.createActions(MailActions);
  43. 43. // stores/MailStore.js import alt from '../dispatcher'; import MailActions from '../actions/MailActions'; class MailStore { constructor() { this.state = { loading: false, error: false, mails: [] }; this.bindActions(MailActions); } onGetMails() { this.setState({ loading: true, error: false }); } onGetMailsSuccess(response) { this.setState({ loading: false, mails: response.result }); } onGetMailsFail(err) { this.setState({ loading: false, error: err, mails: [] }); } } export default alt.createStore(MailStore, 'MailStore');
  44. 44. // components/MailTableComponent.js import MailRow from './MailRowComponent'; import MailActions from '../actions/MailActions'; import MailStore from '../stores/MailStore'; class MailTable extends React.Component { constructor(props) { super(props); this.state = MailStore.getState(); this.onMailChange = this.onMailChange.bind(this); } componentDidMount() { MailStore.listen(this.onMailChange); MailActions.getMails(); } componentWillUnmount() { MailStore.unlisten(this.onMailChange); } onMailChange(state) { this.setState(state); } render() { if (this.state.loading) { return <p>Carregando emails...</p> } if (!this.state.mails.length) { return <p>Nenhum email por enquanto.</p> } return ( <table className="mails-table"> <thead>...</thead> <tbody> {this.state.mails.map((mail) => { return <MailRow mail={mail} /> })} </tbody> </table> ); } }
  45. 45. // components/MailTableComponent.js import MailRow from './MailRowComponent'; import MailActions from '../actions/MailActions'; import MailStore from '../stores/MailStore'; class MailTable extends React.Component { constructor(props) { super(props); this.state = MailStore.getState(); this.onMailChange = this.onMailChange.bind(this); } ... }
  46. 46. // components/MailTableComponent.js import MailRow from './MailRowComponent'; import MailActions from '../actions/MailActions'; import MailStore from '../stores/MailStore'; class MailTable extends React.Component { ... componentDidMount() { MailStore.listen(this.onMailChange); MailActions.getMails(); } componentWillUnmount() { MailStore.unlisten(this.onMailChange); } onMailChange(state) { this.setState(state); } ... }
  47. 47. // components/MailTableComponent.js import MailRow from './MailRowComponent'; import MailActions from '../actions/MailActions'; import MailStore from '../stores/MailStore'; class MailTable extends React.Component { ... render() { if (this.state.loading) { return <p>Carregando emails...</p> } if (!this.state.mails.length) { return <p>Nenhum email por enquanto.</p> } return ( <table className="mails-table"> <thead>...</thead> <tbody> {this.state.mails.map((mail) => { return <MailRow mail={mail} /> })} </tbody> </table> ); } }
  48. 48. “simplificar”
  49. 49. O que ele pode fazer por nós alta escalabilidade fácil manutenção isomorfismo native apps com react-native programação reativa
  50. 50. Quem já usa airbnb netflix yahoo asana atlassian coursera bbc deezer dropbox facebook instagram imdb imgur marvelapp periscope reddit salesforce uber whatsapp globoplay
  51. 51. (brinks)
  52. 52. Obrigado! { github: “CezarLuiz0”, twitter: “cezar_luiz”, email: “cezarluiz.c@gmail.com” }

×