Friday, September 30, 2016

My Basic understanding of Redux

I extracted these points from Dan Abramov's Egg Head Video

First Principle: 
Everything that changes in application including the Data and the UI state is contained in the single Object called State or State Tree OR
The whole state of application is a single javascript object
  1. All mutations and changes to the state are explicit

Second Principle
State Tree is READ-ONLY
  1. cannot modify or write to state tree
  2. To change state we need to dispatch an action
    1. Action is object describing the change
Any data that gets into the Redux application gets there by actions

Third Principle: To describe state mutations we have to write a pure function that takes previous state, action dispatched and returns the next state of the app, this is called the Reducer
reducer(state, action) { 
 return mutate(state) 

Bare Minimum Redux App
const { createStore } = Redux;
const store = createStore(counter);

const render = () => {
  document.body.innerText = store.getState();

render(); // Initial State

document.addEventListener('click', () => {
  store.dispatch({ type: 'INCREMENT' });

Observations/ Assumptions/ Assertions:
  1. UI or View layer is most predictable when it is described as a pure function of the application state (pioneered by ReactJS)
  2. State Mutations in app need to be described as a pure function (takes previous state and action dispatched and returns next state)
  3. To avoid complex reducers, use reducer composition i.e. extract reducer 
  4. Definitions

State: Minimal representation of the data in application
Action: Minimal representation of the change to the data 
  1. Action can have any structure 
    1. The only requirement is it has type property is not undefined
      1. usage of strings as the type is recommended as strings are serializable
  2. Components don’t know how actions are performed, they simply dispatch action with the accurate type and needed arguments

Pure Functions: Return value depends solely on the values of their arguments
  • do not have observable side affects, e.g.  network or db calls
  • predictable
  • do not modify values passed to them

Impure Functions: May call db, network, operate on DOM
  • have side affects
  • override values passed to them

Reducer: Takes the state and action as arguments and return new state

Wednesday, August 3, 2016

Tuesday, February 4, 2014

Thursday, October 10, 2013

running jruby in jmx console

If you want to play with the MBeans and their properties but prefer ruby

jconsole -J-Djava.class.path=$JDK_HOME/lib/jconsole.jar:$JDK_HOME/lib/tools.jar:/Users/konurur/.rvm/rubies/jruby-1.6.2/lib/jruby.jar -J-Dcom.sun.demo.jconsole.console.language=jruby  -pluginpath $JDK_HOME/demo/scripting/jconsole-plugin/jconsole-plugin.jar 

Wednesday, March 27, 2013

Jruby on rails multiple datasources on jboss with warble

inside warble.rb
  config.webxml.jndi = ["jdbc/DS1", "jdbc/DS2","jdbc/DS3","jdbc/DS4"]

inside jboss-web-xml





inside web.xml.erb

 <% if webxml.jndi then webxml.jndi.each do |jndi| %>
        <res-ref-name><%= jndi %></res-ref-name>
    <% end; end %>

Wednesday, February 29, 2012

Cucumber Rspec Example

After trying to wrap my head around Behavior Driven Development and getting sick of the text book example from Pragmatic Bookshelf's The Rspec Book.

I thought I should really develop something so trivial and part of my life to really understand the BDD philosophy and methodology.

So I gave a shot at the best thing I do in my life, making tea for my wife, I am pretty sure she loves my Tea because she doesn't have to do it in the early morning.

so heres how the feature file looks like

# Home Maker Morning Chores
# language: en
@good_morning @make_tea
Feature: Home Maker Prepares Tea
  In order to start a morning
  As a Home Maker of The Home
  I want to prepare Tea

  Scenario: Making Tea for 2 with Tea Bags
    Given Tea Maker
    When making 2 cups of tea
    Then add 1 cup milk
    And  add 1 Cup Water
    And add 2 spoons Sugar
    And add 4 tea bags
    Then print tea making steps

and the code is here