Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/modules / ___dist / exotic / @examples / composition-with-lifting.js
Size: Mime:
"use strict";

const _require = require("../../deps"),
      cast = _require.cast,
      is = _require.is,
      indexByProp = _require.indexByProp;

const _require2 = require("../../chain-able/src/deps/examples/fixture"),
      fixture = _require2.fixture;

const _require3 = require("../../chain-able/src/deps/PlayDoe"),
      CompositionHack = _require3.CompositionHack,
      Master = _require3.Master;

const overArgs = require("../../chain-able/src/coerce/coerceOverArgs"); // https://paucls.wordpress.com/2017/03/04/ddd-building-blocks-value-objects/
// @TODO add support for Observable
// add additional type casts
// Composition
//   .reshape({
//     skus: indexBy('identifier'),
//     pricing: PRICING,
//   })
//   .lift('children')
//   .schema({
//     image: TypeImage,
//     navtype: Type.Nav(),
//     products: [PRODUCT],
//   })


const fake = {
  eh: {
    skus: [{
      identifier: 'skusie',
      value: 'oh'
    }],
    shouldMatch: [{
      label: 'uh oh',
      value: 'oh no'
    }],
    children: {
      products: [{
        'identifier': 'prod-eh',
        'properties?': 'true',
        'digimon': '10.1',
        'nummy': '100'
      }]
    }
  }
};
const composition = new CompositionHack(fixture);
console.log('composed'); // @TODO
// https://stackoverflow.com/questions/35538351/ramda-js-lens-for-deeply-nested-objects-with-nested-arrays-of-objects
// @TODO RESHAPE MATCHING PATTERN: ANY `ARRAY` THAT HAS HAS OBJECTS THAT HAVE PROPERTIES OF LABEL, VALUE
// .lift('children')
// .lift('properties')
// .reshapeWhere({ products: isArray }, indexByProp('identifier'))

composition.liftRecursive('children') // .reshape({
//   products: indexByProp('identifier'),
//   skus: indexByKeyVal('identifier', 'value'),
//   // pricing: PRICING,
// })
.reshapeWhere([{
  value: is.isStringOrNumber,
  label: is.isStringOrNumber
}], indexByProp('label')).reshapeWhere(is.isBooleanLike, cast.fromIshToBoolean).reshapeWhere(is.isNumberish, cast.toNumber) // @TODO how do we take numbers without decimals? when surroundedBy?
.reshapeWhere(is.isNumberishWithDecimals, cast.toFixedDigits(2)); // composition
//   .liftRecursive('children')
//   .reshape({
//     products: indexByKeyVal('identifier', 'properties?'),
//     skus: indexByKeyVal('identifier', 'value'),
//   })
//   .reshapeWhere(
//     [{ value: String, label: String }],
//     indexByProp('label')
//   )
//   .reshapePrimitive(BooleanType)
// could also build our stuff with a `beforeSchema`
// and `afterSchema` which would generate our coercsion playdoe stuff
// const coerceObj2 = CoerceChain(coerceMyObjArgument).schema({
//   name: '?String',
//   children: {
//     products: Array,
//   },
//   properties: {
//     iteminfo: {
//       categoryids: Array,
//       additionalinfo: Array,
//     },
//     state: {
//       selectedFacets: Array,
//       sorting: [
//         {
//           options: Array,
//           selectedname: String,
//         },
//       ],
//       productcount: Number(1),
//     },
//   },
//   facets: Array,
// })
// const TypeImage = Type.image('default url')
//
// Type.registerProperty('*.image', TypeImage)
// Type.registerProperty('*.identifier', Type.id())
// Type.register('Nav').enum('identifier', 'moose', 'eh').default('identifier')
//
// /* prettier-ignore */
// Composition
//   .reshape({
//     skus: indexBy('identifier'),
//     pricing: PRICING,
//   })
//   .lift('children')
//   .schema({
//     image: TypeImage,
//     navtype: Type.Nav(),
//     products: [PRODUCT],
//   })