This is the presentation I gave at the "First LT Meeting #2" for the students on May 9, 2020.
ॳΊͯͷ-5ձLPIFJUBLBIBTIJ"DUJPO$BCMFΛͬͯใػೳΛ࣮͍ͯ͠·͢
View Slide
ࣗݾհ "DUJPO$BCMFͷੈք؍ ͲͷΑ͏ʹ࣮͍ͯ͠Δͷ͔ ·ͱΊ ࢀߟαΠτ˞Ͱ͖Δ͚ͩਖ਼֬ͳ༰Λ͑ΔΑ͏ʹ৺͕͚ͯ·͕͢ɺؒҧͬͨ༰Λͯͨ͠Β͍͢·ͤΜ˞ͦͷࡍڭ͑ͯͩ͘͞Δͱେม༗͍Ͱ͢͜ͷൃදͷ༰
LPIFJUBLBITIJ ߴڮߤฏࡀํͷେֶӃͰྟচ৺ཧΛษڧ͍͕ͯͨ͠ɺ࠳ંͯ͠ϓϩάϥϛϯάʹͨ·ͨ·ग़ձ͏ͨ·ͨ·'+03%#005$".1Λݟ͚ͭɺ݄ʹೖձ݄͔Βबۀ༧ఆझຯϘʔυήʔϜͱಡॻͱԹઘ ݈߁ϥϯυࠓεΫϥϜ։ൃͱࣗ࡞ΞϓϦ։ൃʹऔΓΜͰ͍·ࣗ͢ݾհ
ใػೳΛ࣮தࣗଞͷਓͷߘΛݟΔͨΊʹɺҰճҰճϖʔδΛϦϩʔυͨ͘͠ͳ͍ɻͦͷͨΊɺϖʔδϦϩʔυͳ͠ͰϦΞϧλΠϜʹߘɺฤूɺআ͕දࣔ͞ΕΔΑ͏ʹ͍ͨ͠ɻͦͷϦΞϧλΠϜදࣔΛ࣮ݱ͢ΔͨΊʹ伴ͱͳͬͯ͘Δͷ͕ํ௨৴
ํ௨৴Λ࣮ݱ͢ΔͨΊʹ3BJMT͕ఏڙ͍ͯ͠ΔϑϨʔϜϫʔΫ͕"DUJPO$BCMF
ҰίωΫγϣϯཱ͕֬͞ΕΔͱɺઐ༻ͷϓϩτίϧ্ͰΓͱΓΛߦ͏Α͏ʹͳΓ·͢ɻ͜ΕʹΑΓɺແཧͳ͘ํ௨৴͕Ͱ͖ΔΑ͏ʹͳΓ·ͨ͠ɻ"DUJPO$BCMFͰ8FC4PDLFU௨৴͕Ͱ͖Δ)551ίωΫγϣϯ8FC4PDLFUίωΫγϣϯ
ΫϥΠΞϯτ͕αʔόʔʹϦΫΤετΛૹΓɺͦΕʹԠͯ͠ɺαʔόʔଆ͕ϨεϙϯεΛฦ͢͜ͱ͕લఏͷͨΊɺϦΫΤετͳ͠Ͱαʔόʔଆ͕ೳಈతʹσʔλΛૹΔ͜ͱ͕Ͱ͖·ͤΜͰͨ͠ɻ9.-3FRVFTU௨৴ͰϦΫΤετϨεϙϯε
$PNFU௨৴Ͱͦͦ)551ίωΫγϣϯɺϦΫΤετΛૹͬͯϨεϙϯε͕ฦ͖ͬͯͨΒΫϩʔζ͢ΔͨΊɺ͜ΕΛҙਤతʹΫϩʔζͤ͞ͳ͍͜ͱͰɺํ௨৴Λ࣮ݱ͠Α͏ͱͨ͠ͷ͕$PNFU௨৴Ͱ͢ɻ)551ίωΫγϣϯͷຊདྷͷ͍ํͱҟͳΔͨΊɺཪٕతͳͷͷΑ͏Ͱ͢ɻ)551ίωΫγϣϯ
"DUJPO$BCMFͷੈք؍
"DUJPO$BCMFͷੈք؍8FC4PDLFUίωΫγϣϯDPOTVNFSDIBOOFMEBUBΫϥΠΞϯταʔόʔ
8FC4PDLFUίωΫγϣϯͷத8FC4PDLFUίωΫγϣϯDIBOOFMEBUBDPOTVNNFS͕DIBOOFMʹೖΓɺσʔλड͚औΓՄೳঢ়ଶʹͳΔ͜ͱΛTVCTDSJCFͱ͍͏DPOTVNFSEBUB͕DIBOOFMʹૹΒΕͯɺDPOTVNFS͕डऔՄೳঢ়ଶʹͳΔ͜ͱΛCSPBEDBTUͱ͍͏
ݱஈ֊ͷใػೳΛ͓ݟͤ͠·͢
͜ΕͲͷΑ͏ʹ࣮ͨ͠ͷ͔
ใϖʔδΛ։͍ͨ࣌ͷॲཧͷྲྀΕ7VFίϯϙʔωϯτ[email protected]UJNFMJOFWVF7VFKTଆ3BJMTଆBQQDIBOOFMTDIBOOFMSCDPOOFDUJPOSC[email protected][email protected]ᶆαϒεΫϥΠϒ͞ΕͨΒɺաڈͷใҰཡͷσʔλΛૹΔᶃίϯϙʔωϯτ͕DSFBUF͞Εͨ࣌ʹ8FC4PDLFUίωΫγϣϯΛ࡞Ζ͏ͱ͢Δᶄ[email protected]ͳΒίωΫγϣϯΛཱ֬͢ΔᶅίωΫγϣϯཱ͕֬͞ΕͨΒαϒεΫϥΠϒ͢Δ
7VFίϯϙʔωϯτ[email protected]UJNFMJOFWVF7VFKTଆ3BJMTଆBQQDIBOOFMTDIBOOFMSCDPOOFDUJPOSC[email protected][email protected]
8FC4PDLFUίωΫγϣϯͷཱ֬ʹؔ͢ΔॲཧΛهड़͍ͯ͠·͢ɻ͜͜Ͱɺ[email protected]Ͱ8FC4PDLFUίωΫγϣϯʹJEΛ༩͍͑ͯ·͢ɻ͜͜Ͱɺ[email protected]ΛίωΫγϣϯͷJEʹ͍ͯ͠·͢ɻDPPLJF͔Β[email protected]ͷใΛಡΈऔ͍ͬͯ·͢ɻ͠ɺDPPLJFʹ[email protected]ͷใ͕ͳ͚ΕɺίωΫγϣϯΛཱ֬͠·ͤΜɻDPOOFDUJPOSCΛݟ͍ͯ͘۩ମతͳίʔυ͕ཉ͍͠module ApplicationCableclass Connection < ActionCable::Connection::Baseidentified_by :current_userdef connectself.current_user = find_verified_userendprivatedef find_verified_userif verified_user = User.find_by(id: store["user_id"])verified_userelsereject_unauthorized_connectionendenddef storecookies.encrypted[Rails.application.config.session_options[:key]]endendend
"DUJPO$BCMFͷDIBOOFMʹ͓͚ΔDPOUSPMMFSͷׂΛ୲͍·͢ɻͦͷͨΊɺ$36%ͷॲཧΛهड़ͯ͠·͢ɻσʔλΛϒϩʔυΩϟετ͢Δ͜ͱͰɺνϟωϧʹσʔλΛૹΓ·͢ɻ·ͨɺαϒεΫϥΠϒͨ࣌͠ɺαϒεΫϥΠϒ͕ऴΘͬͨ࣌ͷॲཧΛॻ͖·͢ɻ͜͜ͰɺαϒεΫϥΠϒͨ࣌͠ʹɺաڈͷใҰཡΛૹΔΑ͏ʹ͍ͯ͠·͢ɻ[email protected]Λݟ͍ͯ͘۩ମతͳίʔυ͕ཉ͍͠class TimelinesChannel < ApplicationCable::Channelinclude Rails.application.routes.url_helpersdef subscribedstream_from "timelines_channel"timelines = Timeline.order(created_at: :asc)transmit({ event: "timelines", current_user: format_current_user, timelines: format_timelines(timelines) })enddef unsubscribed# Any cleanup needed when channel is unsubscribedenddef create_timeline(data)@timeline = Timeline.create!(user_id: current_user.id, description: data["description"])ActionCable.server.broadcast "timelines_channel", { event: "create_timeline", timeline: format_timeline(@timeline) }enddef update_timeline(data)@timeline = Timeline.find_by(id: data["id"])@timeline.update(description: data["description"])ActionCable.server.broadcast "timelines_channel", { event: "update_timeline", timeline: format_timeline(@timeline) }enddef delete_timeline(data)@timeline = Timeline.find_by(id: data["id"])@timeline.destroyActionCable.server.broadcast "timelines_channel", { event: "delete_timeline", timeline: format_timeline(@timeline) }endend
͔Γ͍͢Α͏ʹҰ෦ൈਮͱɺվมΛߦ͍ͬͯ·͢ɻ͜͜ʹɺϑϩϯτΤϯυଆͷ[email protected]ʹؔ͢Δใ͕·ͱ·͍ͬͯ·͢CSPBEDBTU͞Εͨσʔλ\BDUJPODSFBUF UJNFMJOF!UJNFMJOF^ͳͲͷܗͰૹΔΑ͏ʹ͍ͯ͠·͢ɻͦ͜Ͱɺड͚औͬͨσʔλͷBDUJPO͕ͳΜͳͷ͔ͰɺॲཧΛม͑ΔΑ͏ʹ͍ͯ͠·͢ɻUJNFMJOFTDIBOOFMWVFΛݟ͍ͯ͘this.timelinesChannel = this.$cable.subscriptions.create("TimelinesChannel", {connected: () => {console.log('connected successfully')},disconnected: () => {},received: (data) => {switch (data.event) {case 'timelines':data.timelines.forEach((timeline) => {this.timelines.unshift(timeline)})breakcase 'create_timeline':this.timelines.unshift(data.timeline)breakcase 'update_timeline':this.timelines.forEach((timeline) => {if (timeline.id === data.timeline.id) {timeline.description = data.timeline.description}})breakcase 'delete_timeline':this.timelines.forEach((timeline, i) => {if (timeline.id === data.timeline.id) {this.timelines.splice(i, 1)}})break}}})
"DUJPO$BCMFͷੈք؍Λ௫Ήͷ͕ͱͯେมͰͨ͠ɻͦ͜ͰɺͦͷഎܠͱͳΔ8FC4PDLFUͷ֓ཁΛֶͿ͜ͱͰɺͣͬͱཧղ͘͢͠ͳΓ·ͨ͠ɻ+BWB4DSJQUଆͰDIBOOFMͰఆٛ͞ΕͨϝιουΛݺͨΓɺϝιουҰͭͰɺσʔλΛૹΕͨΓ͢ΔͷͰɺ3BJMTͱ7VFKTͷσʔλͷΓऔΓ͕ൺֱత؆୯ʹͰ͖·ͨ͠ɻखܰʹϦΞϧλΠϜͷΞΫγϣϯ͕࣮Ͱ͖ΔҰํͰɺগ͠खͷࠐΜͩ͜ͱΛΖ͏ͱ͢ΔͱɺͱͯϋϚΓ·ͨ͠ ࣗͷྗෆͳ͚ͩͰ͕͢ʜɻ͋ͱগ͠Ͱ13Λग़ͤΔͷͰ͕͢ɺͦͷগ͠ͷͱ͜ΖͰ֨ಆதͰ͢ɻ۩ମతʹͲΜͳͱ͜ΖʹϋϚͬͨͷ͔ɺۤ͠Μͩͷ͔ޙϒϩάʹॻ͖͍ͨͱࢥ͍·͢ɻ·ͱΊ
3BJMTΨΠυd"DUJPO$BCMFͷ֓ཁd IUUQTSBJMTHVJEFTKQ[email protected]@PWFSWJFXIUNM8FC4PDLFU IUUQTKBXJLJQFEJBPSHXJLJ8FC4PDLFU࣮ࡍͷ13ͪ͜Β IUUQTHJUIVCDPNGKPSEMMDCPPUDBNQQVMMࢀߟʹ͍͍ͤͯͨͩͨ͞αΠτ
͝੩ௌ༗Γ͏͍͟͝·ͨ͠