Skip to content

tkh44/retarget

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm version Build Status codecov

retarget

selectors via targets

Install

npm i retarget -S

or

yarn add retarget

import retarget from 'retarget'

const STATE = {
  profile: {
    name: {
      first: 'Waylon',
      last: 'Jennings'
    }
  }
}

const lastNameSelector  = retarget`profile.name.last`

console.log(lastNameSelector(STATE)) // logs "Jennings"

Composing

It is possible to compose multiple selectors together to create a new one.

import retarget from 'retarget'

const STATE = {
  users: {
    '1': {
      profile: {
          name: {
            first: 'Waylon',
            last: 'Jennings'
          }
        }
      }
    }
}

const lastNameSelector  = retarget`profile.name.last`

const createUserSelector = (id) =>
  retarget`users.${id}${lastNameSelector}`


const userSelector = createUserSelector(1)

console.log(userSelector(STATE)) // logs "Jennings"

API

retarget function

import retarget from 'retarget'

const selector = retarget`dot.seperated.path.to.value`

const state = {/* Huge object */}
selector(state) // returns the value at "dot.seperated.path.to.value"

Returns

retarget returns a function that when passed an obj, attempts to get the value for the given path.

About

Focus on targets with selectors

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published