JSFiddle - React, Tailwind, and code Playground
by nickadeemus2002
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.7.2/redux.min.js"></script>
<div ng-app="app">
<div ng-controller="emp">
<input type="text" ng-model="a" />
<p> a = {{a}} </p>
<p> b = {{b}} </p>
</div>
</div>
JavaScript
/**
* Redux Functions
*/
var redux = window.Redux;
// store [single function]
function Store(reducer, initialState){
this._state = initialState;
this._reducer = reducer;
this._listeners = [];
}
Store.prototype = {
constructor: Store,
getState: function(){
return this._state;
},
getListeners: function(){
return this._listeners;
},
dispatch:function(action){
this._state = this._reducer(this._state, action);
this._listeners.forEach(function(listener){
listener();
});
},
subscribe: function(listener){
this._listeners.push(listener);
//unsubscribe
return function(){
this._listeners = this._listeners.filter(function(l){
return l !== listener;
});
}
}
};
//reducers [pure functions]
var reducer = function(state, action){
//basic math
if(action.type === "INCREMENT"){
return state + action.payload;
}
if(action.type === "DECREMENT"){
return state - action.paylod;
}
return state;
};
//actions
var incrementAction = function(){
return { type: "INCREMENT"};
}
var decrementAction = function(){
return { type: "DECREMENT"};
}
var variableAction = function(action, data){
return {
type: action,
payload: data
};
}
//biz
var store = new Store(reducer, 0);
console.log("store.getState() => ", store.getState());
var unsubscribe = store.subscribe(function listener(){
console.log('subscribed! store.getState() =>', store.getState());
});
var unsubscribe2 = store.subscribe(function listener2(){
console.log('another subscribed! store.getState() =>', store.getState());
});
console.log("store.getListeners() => ", store.getListeners());
store.dispatch(variableAction("INCREMENT", 10));
/**
* Redux Lib
*/
/**
* testing $digest
*/
var app = angular.module("app",[]);
app.controller("emp",[
"$scope",
"$rootScope",
function($scope, $rootScope){
$scope.a = 1;
$scope.b =2;
$scope.c =3;
$scope.o = {
person1: "makayla",
person2:...