Nanotechnology Promises Much

    redux-value-ql

    1.0.36 • Public • Published

    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

    Install

    npm i redux-value-ql

    DownloadsWeekly Downloads

    3

    Version

    1.0.36

    License

    MIT

    Unpacked Size

    470 kB

    Total Files

    7

    Last publish

    Collaborators

    • zhukyuri