Redux Getting Started Tutorial 1

Source: Internet
Author: User

Novice look online Some redux articles, very easy to be confused by those concepts, I follow the official example to write a series of novice tutorials, we can refer to, reproduced please indicate the source

Tutorial 1 is no use of react, and does not use NPM these things, it is very suitable for everyone to understand the redux in essence.

1. Load redux.js <script src= "Https://npmcdn.com/[email protected]/dist/redux.min.js" ></script>

2.html

<div id= "Container" >
<button onclick= "Select (' A ')" >click a</button>
<button onclick= "Select (' B ')" >click b</button>
<button onclick= "Select (' C ')" > click c</button>
<div id= "Show" > </div>
</div>

3.js

Handlestore equivalent to a function of the control store

function Handlestore (store, action) {
if (typeof store = = = undefined) {
return false;
}

Switch (action.type) {
Case ' A ': return ' this is a '; Break
Case ' B ': Return ' this is B '; Break
Case ' C ': Return ' this is C '; Break
Default:return ' This is None '; Break
}
}

Store created via CreateStore
var store = Redux.createstore (Handlestore);

Store changes can be observed through subscribe

Store.subscribe (function () {
document.getElementById (' show '). InnerHTML = Store.getstate (). toString ();
});

Initialize execution

Select (");

function Select (item) {
Store.dispatch ({
Type:item
});
}

All source code:

<! DOCTYPE html>

  

Redux Getting Started Tutorial 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.