SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
Reflux
Kyoto.js vol. 13
2017.7.30
• (Twitter@kamiyam)
•
• Engineer
•
RefluxJS
is
Reflux is
is
Ref. https://github.com/reflux/refluxjs#overview
1.creating actions
2.creating stores
3.hooking stores to React components
Ref. https://github.com/reflux/refluxjs#usage
creating actions.
Implements Action
var Actions = Reflux.createActions([
"statusUpdate",
"statusEdited",
"statusAdded"
]);
// Actions object now contains the actions
// with the names given in the array above
// that may be invoked as usual
Actions.statusUpdate();
creating stores.
Manually Listenable Store
class StatusStore extends Reflux.Store
{
constructor()
{
super();
this.state = {flag:’OFFLINE’};
// <- set store's default state much like in React
this.listenTo(statusUpdate, this.onStatusUpdate);
// listen to the statusUpdate action
}
onStatusUpdate(status)
{
var newFlag = status ? 'ONLINE' : 'OFFLINE';
this.setState({flag:newFlag});
}
}
var Actions = Reflux.createActions([
‘firstAction’,
‘secondAction’
]);
class StatusStore extends Reflux.Store
{
constructor()
{
super();
this.listenables = Actions;
}
onFirstAction()
{
// calls on Actions.firstAction();
}
onSecondAction()
{
// calls on Actions.secondAction();
Auto Listenable Store
hooking stores to
React components.
Set simple Store
class MyComponent extends Reflux.Component
{
constructor(props)
{
super(props);
this.state = {};
// our store will add its own state to the
component's
this.store = StatusStore;
// <- just assign the store class itself
}
render()
{
var flag = this.state.flag; // <- flag is mixed in
from the StatusStore
return <div>User is {flag}</div>
}
}
Set multiple Stores
class MyComponent extends Reflux.Component
{
constructor(props)
{
super(props);
this.state = {type:’admin'};
// <- note that we can still use normal state
this.stores = [StatusStore, AnotherStore];
this.storeKeys = ['flag', 'info'];
}
render()
{
var flag = this.state.flag;
var info = this.state.info;
var type = this.state.type;
return <div>User is {flag}, info: {info}, type:
{type}</div>
}
}
Did not work 

componentWillReceiveProps?
Manually Set State
class MyComponent extends Reflux.Component
{
constructor(props)
{
super(props);
this.mapStoreToState(MyStoreClass, function(fromStore){
var obj = {};
if (fromStore.color)
obj.color = fromStore.color;
if (fromStore.data && fromStore.data.classToUse)
obj.class = fromStore.data.classToUse;
return obj;
});
}
render()
{
return <p className={this.state.class}>The color is:
{this.state.color}</p>;
}
}
Examples
Simple Fully Functioning Example
var Actions = Reflux.createActions([
'increment',
'decrement',
'changeBy'
]);
Simple Fully Functioning Example
class CounterStore extends Reflux.Store
{
constructor()
{
super();
this.state = {count: 0};
this.listenables = Actions;
}
onIncrement()
{
this.setState({count: this.state.count+1});
}
onDecrement()
{
this.setState({count: this.state.count-1});
}
onChangeBy(amount)
{
this.setState({count: this.state.count+amount});
}
}
Simple Fully Functioning Example
class Counter extends Reflux.Component
{
constructor(props)
{
super(props);
this.store = CounterStore;
}
render()
{
return <div>{this.state.count}</div>;
}
}
Simple Fully Functioning Example
ReactDOM.render
(
<Counter/>,
document.querySelector('#react-root')
);
setInterval(Actions.increment, 1000);
DEMO
kyoto.js13

Contenu connexe

Similaire à kyoto.js13

How to use redux with react hooks in react native application
How to use redux with react hooks in react native applicationHow to use redux with react hooks in react native application
How to use redux with react hooks in react native applicationKaty Slemon
 
Damian Kmiecik - Road trip with Redux
Damian Kmiecik - Road trip with ReduxDamian Kmiecik - Road trip with Redux
Damian Kmiecik - Road trip with ReduxPROIDEA
 
Reactивная тяга
Reactивная тягаReactивная тяга
Reactивная тягаVitebsk Miniq
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingBinary Studio
 
Introduction to ReactJS and Redux
Introduction to ReactJS and ReduxIntroduction to ReactJS and Redux
Introduction to ReactJS and ReduxBoris Dinkevich
 
Background Jobs with Resque
Background Jobs with ResqueBackground Jobs with Resque
Background Jobs with Resquehomanj
 
React and MobX: A Truly Reactive App
React and MobX:  A Truly Reactive AppReact and MobX:  A Truly Reactive App
React and MobX: A Truly Reactive AppJacob Orshalick
 
Stay with React.js in 2020
Stay with React.js in 2020Stay with React.js in 2020
Stay with React.js in 2020Jerry Liao
 
vJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemvJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemAndres Almiray
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux IntroductionNikolaus Graf
 
Redux for ReactJS Programmers
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS ProgrammersDavid Rodenas
 
An Introduction to Ruby on Rails
An Introduction to Ruby on RailsAn Introduction to Ruby on Rails
An Introduction to Ruby on RailsJoe Fiorini
 
Enhance react app with patterns - part 1: higher order component
Enhance react app with patterns - part 1: higher order componentEnhance react app with patterns - part 1: higher order component
Enhance react app with patterns - part 1: higher order componentYao Nien Chung
 
A full introductory guide to React
A full introductory guide to ReactA full introductory guide to React
A full introductory guide to ReactJean Carlo Emer
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today Nitin Tyagi
 

Similaire à kyoto.js13 (20)

How to use redux with react hooks in react native application
How to use redux with react hooks in react native applicationHow to use redux with react hooks in react native application
How to use redux with react hooks in react native application
 
Damian Kmiecik - Road trip with Redux
Damian Kmiecik - Road trip with ReduxDamian Kmiecik - Road trip with Redux
Damian Kmiecik - Road trip with Redux
 
Reactивная тяга
Reactивная тягаReactивная тяга
Reactивная тяга
 
Redux Tech Talk
Redux Tech TalkRedux Tech Talk
Redux Tech Talk
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
 
Let's react - Meetup
Let's react - MeetupLet's react - Meetup
Let's react - Meetup
 
The JavaFX Ecosystem
The JavaFX EcosystemThe JavaFX Ecosystem
The JavaFX Ecosystem
 
Introduction to ReactJS and Redux
Introduction to ReactJS and ReduxIntroduction to ReactJS and Redux
Introduction to ReactJS and Redux
 
Background Jobs with Resque
Background Jobs with ResqueBackground Jobs with Resque
Background Jobs with Resque
 
Vuex
VuexVuex
Vuex
 
React and MobX: A Truly Reactive App
React and MobX:  A Truly Reactive AppReact and MobX:  A Truly Reactive App
React and MobX: A Truly Reactive App
 
Stay with React.js in 2020
Stay with React.js in 2020Stay with React.js in 2020
Stay with React.js in 2020
 
vJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemvJUG - The JavaFX Ecosystem
vJUG - The JavaFX Ecosystem
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
Redux for ReactJS Programmers
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS Programmers
 
An Introduction to Ruby on Rails
An Introduction to Ruby on RailsAn Introduction to Ruby on Rails
An Introduction to Ruby on Rails
 
Enhance react app with patterns - part 1: higher order component
Enhance react app with patterns - part 1: higher order componentEnhance react app with patterns - part 1: higher order component
Enhance react app with patterns - part 1: higher order component
 
A full introductory guide to React
A full introductory guide to ReactA full introductory guide to React
A full introductory guide to React
 
React outbox
React outboxReact outbox
React outbox
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 

Plus de kamiyam .

Socket.ioとBabylonJSで作ったIoT的ななにか
Socket.ioとBabylonJSで作ったIoT的ななにかSocket.ioとBabylonJSで作ったIoT的ななにか
Socket.ioとBabylonJSで作ったIoT的ななにかkamiyam .
 
Managing multi-package repositories
Managing multi-package repositoriesManaging multi-package repositories
Managing multi-package repositorieskamiyam .
 
TypeScript + Express
TypeScript + ExpressTypeScript + Express
TypeScript + Expresskamiyam .
 
プラベワークのススメ
プラベワークのススメプラベワークのススメ
プラベワークのススメkamiyam .
 
HomeKitとNode.jsを使ってSiriでコントロールするなにか
HomeKitとNode.jsを使ってSiriでコントロールするなにかHomeKitとNode.jsを使ってSiriでコントロールするなにか
HomeKitとNode.jsを使ってSiriでコントロールするなにかkamiyam .
 
Kinectを使った インタラクティブコンテンツを作った話
Kinectを使った インタラクティブコンテンツを作った話Kinectを使った インタラクティブコンテンツを作った話
Kinectを使った インタラクティブコンテンツを作った話kamiyam .
 
Node.jsでKinectを触ろうとして色々しくじった話
Node.jsでKinectを触ろうとして色々しくじった話Node.jsでKinectを触ろうとして色々しくじった話
Node.jsでKinectを触ろうとして色々しくじった話kamiyam .
 
ヒカ☆ラボ@Osaka NodeBotsハンズオン
ヒカ☆ラボ@Osaka NodeBotsハンズオンヒカ☆ラボ@Osaka NodeBotsハンズオン
ヒカ☆ラボ@Osaka NodeBotsハンズオンkamiyam .
 
Node.js をさりげなく取り入れた 最近のフロントエンド事情について
Node.js をさりげなく取り入れた 最近のフロントエンド事情についてNode.js をさりげなく取り入れた 最近のフロントエンド事情について
Node.js をさりげなく取り入れた 最近のフロントエンド事情についてkamiyam .
 
JavaScript Performance 20160723
JavaScript Performance 20160723JavaScript Performance 20160723
JavaScript Performance 20160723kamiyam .
 
JavaScriptが魅せる新たな世界
JavaScriptが魅せる新たな世界JavaScriptが魅せる新たな世界
JavaScriptが魅せる新たな世界kamiyam .
 
WordBench Osaka #48 About Calypso
WordBench Osaka #48 About CalypsoWordBench Osaka #48 About Calypso
WordBench Osaka #48 About Calypsokamiyam .
 
Async Enhancement
Async EnhancementAsync Enhancement
Async Enhancementkamiyam .
 
はじめてのVue.js
はじめてのVue.jsはじめてのVue.js
はじめてのVue.jskamiyam .
 
Node.jsで始める Modern JavaScript Framework
Node.jsで始める Modern JavaScript FrameworkNode.jsで始める Modern JavaScript Framework
Node.jsで始める Modern JavaScript Frameworkkamiyam .
 
Scalable Node.js with Redis Store
Scalable Node.js with Redis StoreScalable Node.js with Redis Store
Scalable Node.js with Redis Storekamiyam .
 
Gruntの罪と罰
Gruntの罪と罰Gruntの罪と罰
Gruntの罪と罰kamiyam .
 
Node.js勉強会 Framework Koa
Node.js勉強会 Framework KoaNode.js勉強会 Framework Koa
Node.js勉強会 Framework Koakamiyam .
 
知っているつもりで実は知らない 拾う技術捨てる技術
知っているつもりで実は知らない 拾う技術捨てる技術知っているつもりで実は知らない 拾う技術捨てる技術
知っているつもりで実は知らない 拾う技術捨てる技術kamiyam .
 
PhpStormとGrunt.jsで作るCakePHP快適開発環境
PhpStormとGrunt.jsで作るCakePHP快適開発環境 PhpStormとGrunt.jsで作るCakePHP快適開発環境
PhpStormとGrunt.jsで作るCakePHP快適開発環境 kamiyam .
 

Plus de kamiyam . (20)

Socket.ioとBabylonJSで作ったIoT的ななにか
Socket.ioとBabylonJSで作ったIoT的ななにかSocket.ioとBabylonJSで作ったIoT的ななにか
Socket.ioとBabylonJSで作ったIoT的ななにか
 
Managing multi-package repositories
Managing multi-package repositoriesManaging multi-package repositories
Managing multi-package repositories
 
TypeScript + Express
TypeScript + ExpressTypeScript + Express
TypeScript + Express
 
プラベワークのススメ
プラベワークのススメプラベワークのススメ
プラベワークのススメ
 
HomeKitとNode.jsを使ってSiriでコントロールするなにか
HomeKitとNode.jsを使ってSiriでコントロールするなにかHomeKitとNode.jsを使ってSiriでコントロールするなにか
HomeKitとNode.jsを使ってSiriでコントロールするなにか
 
Kinectを使った インタラクティブコンテンツを作った話
Kinectを使った インタラクティブコンテンツを作った話Kinectを使った インタラクティブコンテンツを作った話
Kinectを使った インタラクティブコンテンツを作った話
 
Node.jsでKinectを触ろうとして色々しくじった話
Node.jsでKinectを触ろうとして色々しくじった話Node.jsでKinectを触ろうとして色々しくじった話
Node.jsでKinectを触ろうとして色々しくじった話
 
ヒカ☆ラボ@Osaka NodeBotsハンズオン
ヒカ☆ラボ@Osaka NodeBotsハンズオンヒカ☆ラボ@Osaka NodeBotsハンズオン
ヒカ☆ラボ@Osaka NodeBotsハンズオン
 
Node.js をさりげなく取り入れた 最近のフロントエンド事情について
Node.js をさりげなく取り入れた 最近のフロントエンド事情についてNode.js をさりげなく取り入れた 最近のフロントエンド事情について
Node.js をさりげなく取り入れた 最近のフロントエンド事情について
 
JavaScript Performance 20160723
JavaScript Performance 20160723JavaScript Performance 20160723
JavaScript Performance 20160723
 
JavaScriptが魅せる新たな世界
JavaScriptが魅せる新たな世界JavaScriptが魅せる新たな世界
JavaScriptが魅せる新たな世界
 
WordBench Osaka #48 About Calypso
WordBench Osaka #48 About CalypsoWordBench Osaka #48 About Calypso
WordBench Osaka #48 About Calypso
 
Async Enhancement
Async EnhancementAsync Enhancement
Async Enhancement
 
はじめてのVue.js
はじめてのVue.jsはじめてのVue.js
はじめてのVue.js
 
Node.jsで始める Modern JavaScript Framework
Node.jsで始める Modern JavaScript FrameworkNode.jsで始める Modern JavaScript Framework
Node.jsで始める Modern JavaScript Framework
 
Scalable Node.js with Redis Store
Scalable Node.js with Redis StoreScalable Node.js with Redis Store
Scalable Node.js with Redis Store
 
Gruntの罪と罰
Gruntの罪と罰Gruntの罪と罰
Gruntの罪と罰
 
Node.js勉強会 Framework Koa
Node.js勉強会 Framework KoaNode.js勉強会 Framework Koa
Node.js勉強会 Framework Koa
 
知っているつもりで実は知らない 拾う技術捨てる技術
知っているつもりで実は知らない 拾う技術捨てる技術知っているつもりで実は知らない 拾う技術捨てる技術
知っているつもりで実は知らない 拾う技術捨てる技術
 
PhpStormとGrunt.jsで作るCakePHP快適開発環境
PhpStormとGrunt.jsで作るCakePHP快適開発環境 PhpStormとGrunt.jsで作るCakePHP快適開発環境
PhpStormとGrunt.jsで作るCakePHP快適開発環境
 

Dernier

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 

Dernier (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 

kyoto.js13

  • 4. is
  • 6. is
  • 8.
  • 9. 1.creating actions 2.creating stores 3.hooking stores to React components Ref. https://github.com/reflux/refluxjs#usage
  • 11. Implements Action var Actions = Reflux.createActions([ "statusUpdate", "statusEdited", "statusAdded" ]); // Actions object now contains the actions // with the names given in the array above // that may be invoked as usual Actions.statusUpdate();
  • 13. Manually Listenable Store class StatusStore extends Reflux.Store { constructor() { super(); this.state = {flag:’OFFLINE’}; // <- set store's default state much like in React this.listenTo(statusUpdate, this.onStatusUpdate); // listen to the statusUpdate action } onStatusUpdate(status) { var newFlag = status ? 'ONLINE' : 'OFFLINE'; this.setState({flag:newFlag}); } }
  • 14. var Actions = Reflux.createActions([ ‘firstAction’, ‘secondAction’ ]); class StatusStore extends Reflux.Store { constructor() { super(); this.listenables = Actions; } onFirstAction() { // calls on Actions.firstAction(); } onSecondAction() { // calls on Actions.secondAction(); Auto Listenable Store
  • 15. hooking stores to React components.
  • 16. Set simple Store class MyComponent extends Reflux.Component { constructor(props) { super(props); this.state = {}; // our store will add its own state to the component's this.store = StatusStore; // <- just assign the store class itself } render() { var flag = this.state.flag; // <- flag is mixed in from the StatusStore return <div>User is {flag}</div> } }
  • 17. Set multiple Stores class MyComponent extends Reflux.Component { constructor(props) { super(props); this.state = {type:’admin'}; // <- note that we can still use normal state this.stores = [StatusStore, AnotherStore]; this.storeKeys = ['flag', 'info']; } render() { var flag = this.state.flag; var info = this.state.info; var type = this.state.type; return <div>User is {flag}, info: {info}, type: {type}</div> } }
  • 18. Did not work 
 componentWillReceiveProps?
  • 19. Manually Set State class MyComponent extends Reflux.Component { constructor(props) { super(props); this.mapStoreToState(MyStoreClass, function(fromStore){ var obj = {}; if (fromStore.color) obj.color = fromStore.color; if (fromStore.data && fromStore.data.classToUse) obj.class = fromStore.data.classToUse; return obj; }); } render() { return <p className={this.state.class}>The color is: {this.state.color}</p>; } }
  • 21. Simple Fully Functioning Example var Actions = Reflux.createActions([ 'increment', 'decrement', 'changeBy' ]);
  • 22. Simple Fully Functioning Example class CounterStore extends Reflux.Store { constructor() { super(); this.state = {count: 0}; this.listenables = Actions; } onIncrement() { this.setState({count: this.state.count+1}); } onDecrement() { this.setState({count: this.state.count-1}); } onChangeBy(amount) { this.setState({count: this.state.count+amount}); } }
  • 23. Simple Fully Functioning Example class Counter extends Reflux.Component { constructor(props) { super(props); this.store = CounterStore; } render() { return <div>{this.state.count}</div>; } }
  • 24. Simple Fully Functioning Example ReactDOM.render ( <Counter/>, document.querySelector('#react-root') ); setInterval(Actions.increment, 1000);
  • 25. DEMO