

import _ from 'lodash'

const fixPath = path =>  ((path.substring(0,1) == '/') ? '': '/') + path

export const toJS = data => {

  if(data && data.toJS) {
    return data.toJS()
  }

  return data
}


export const pathToJS = (data, path, notSetValue) => {
  if(!data) {
    return notSetValue
  }

  const pathArr = fixPath(path).split(/\//).slice(1)

  if(data.getIn) {
    return toJS(data.getIn(pathArr, notSetValue))
  }

  return data
}


export const dataToJS = (data, path, notSetValue) => {
  if(!(data && data.getIn)) {
    return notSetValue
  }

  const dataPath = '/data' + fixPath(path)

  const pathArr = dataPath.split(/\//).slice(1)

  if(data.getIn) {
    return toJS(data.getIn(pathArr, notSetValue))
  }

  return data
}

export const isLoaded = function () {
  if(!arguments || !arguments.length) {
    return true
  }

  return _(arguments).map( a => (a===undefined) ? false : true ).reduce( (a, b) => a && b )
}

export const isEmpty = data => {
  return !(data && _.size(data))
}

@@ -732,24 +732,361 @@
 urn data%0A%7D%0A%0A
+export const snapshotToJS = (snapshot, path, notSetValue) =%3E %7B%0A  if(!(snapshot && snapshot.getIn)) %7B%0A    return notSetValue%0A  %7D%0A%0A  const snapshotPath = '/snapshot' + fixPath(path)%0A%0A  const pathArr = snapshotPath.split(/%5C//).slice(1)%0A%0A  if(snapshot.getIn) %7B%0A    return toJS(snapshot.getIn(pathArr, notSetValue))%0A  %7D%0A%0A  return snapshot%0A%7D%0A%0A
 export const

add snapshot to helper.js