1.0.36 • Published 6 years ago

redux-value-ql v1.0.36

Weekly downloads
10
License
MIT
Repository
github
Last release
6 years ago

redux-value-ql

Redux getting data QL

NPM JavaScript Style Guide

Install

npm install --save redux-value-ql

Usage

Example getting data from state to props

. . .
import { getQL } from 'redux-value-ql';
import { configData, initialData } from './config'

  .  .  .  . 

сonst mapStateToProps = (state) => {

  return getQL(state, configData, initialData);

}

Description

getQL( \<definite object>, \<config> [, \<initial>] );

  • definite object: It is arbitrary object or redux state;
  • config: configuration getting values from \<definite object>
  • initial: initial values ​​before getting data from \<definite object>

Formats config QL

1 - Full path from \<definite object>:

' path_1[.path_2][.path_3][..] '

Return undefined if not path in \<definite object>.

       {
         aaa:  'path_1.path_2', 
         bbb:  'path_1.path_2.path_3.path_4'    
       }

2 - Children properties list from \<definite object> tree structure:

' item_1[ , item_2][ , item_3][ , ...] '

Return undefined if not path in \<definite object>.

       {
         state_1: {
           state_1_1: 'property_name_1, property_name_4',
           state_1_2: {
             state_1_2_3:  'property_name_6, property_name_9'
           }
         }
       }

3 - All children properties from \<definite object> tree structure:

` * ` 
 

Return undefined if not path in \<definite object>.

       {
         state_1: {
           state_1_1: '*',
           state_1_2: {
             state_1_2_3:  '*'
           }
         }
       }

Examples config, result and initial

Example config

config = {
  c: 'state_1.state_1_1.state_1_1_1.state_1_1_1_5',      // <- path  
  d: {
    e: 'state_1.state_1_1.state_1_1_2.state_1_1_2_7',    // <- path
  },
  state_1: {
    state_1_1: {
      state_1_1_1: 'state_1_1_1_3 , state_1_1_1_5',         // list property in 'state_1_1_1'
      state_1_1_2: '*',                                     // all property in 'state_1_1_2' 
      state_1_1_3: 'state_1_1_3_7, state_1_1_3_88, state_1_1_3_99', 
      state_1_1_9: '*',                                                                               
   },
  },
};

Result

// RESULT

{
  a: [],            //   <- from initialData   (see example initialData)
  b: null,          //   <- from initialData
  c: 1115,
  d: { 
    e: 1127
  },
  state_1: {
    state_1_1: {
      state_1_1_1: {
        state_1_1_1_3: 1113, 
        state_1_1_1_5: 1115
      },
      state_1_1_2: {
        state_1_1_2_1: 1121, 
        state_1_1_2_2: 1122,
        state_1_1_2_3: 1123,
        state_1_1_2_4: 1124,
        state_1_1_2_5: 1125,
        state_1_1_2_6: 1126,
        state_1_1_2_7: 1127
      },
       state_1_1_3: {
        state_1_1_3_7: 1137,
        state_1_1_3_88: 'example string',  // <- from initialData  (see example initialData)
        state_1_1_3_99: undefined          // <- property not in state
      },
      state_1_1_9: undefined               // <- property not in state
   }
  }
}

Example initial data

initialData = {
  a: [],    
  b: null,    
  c: 0,  
  d: {
    e: 0,   
  },
  state_1: {
    state_1_1: {
      state_1_1_3: {
        state_1_1_3_88: 'example string'
      }
    }
  }
 };

Example Redux state or other \<definite object>

state = {
   state_1: {
    state_1_1: {
      state_1_1_1: {
        state_1_1_1_1: 1111,
        state_1_1_1_2: 1112,
        state_1_1_1_3: 1113,
        state_1_1_1_4: 1114,
        state_1_1_1_5: 1115,
        state_1_1_1_6: 1116,
        state_1_1_1_7: 1117,
      },
      state_1_1_2: {
        state_1_1_2_1: 1121,
        state_1_1_2_2: 1122,
        state_1_1_2_3: 1123,
        state_1_1_2_4: 1124,
        state_1_1_2_5: 1125,
        state_1_1_2_6: 1126,
        state_1_1_2_7: 1127,
      },
      state_1_1_3: {
        state_1_1_3_1: 1131,

 .  .  .  .  .  

};

Change log

  • 1.0.31:
    • Fixed error when parse initial Path value
    • Edited docs
  • 1.0.28:
    • Return undefined if not path in \<definite object>;
    • Fixed errors;

License

MIT © zhukyuri

1.0.36

6 years ago

1.0.35

6 years ago

1.0.33

6 years ago

1.0.32

6 years ago

1.0.31

6 years ago

1.0.30

6 years ago

1.0.29

6 years ago

1.0.28

6 years ago

1.0.27

6 years ago

1.0.26

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago