Coder Social home page Coder Social logo

Comments (2)

polytypic avatar polytypic commented on June 22, 2024

First of all, I would encourage avoiding augment unless you really need it. It can be handy, but IME it is rarely needed. If you are using augment heavily, you may be missing out on other ways to organize your code. If you are using augment on a model stored in an atom, you can just create separate observable properties instead of using augment.

Note that you can compute multiple extra properties as an object:

L.augment({extra: ({a, b}) => {
  const c = a + b
  const d = c + 2
  return {c, d}
}})

The current implementation of augment intentionally restricts the parameter to be the original unaugmented object. I was under the impression that the order in which object properties are enumerated in JS is undefined, which would make it easy to write bugs if the semi-augmented object were passed in. However, googling more on this I get the impression that it might now be defined in ES2015. It seems difficult to get a really authorative answer on this and as I currently have fever, I'm not going to go and read the JS spec legalese. :) But, it would seem like there is a case for changing the definition of augment so that one can exploit property enumeration order. I'll have to look in to this when I get better.

from partial.lenses.

michshat avatar michshat commented on June 22, 2024

Appreciate the feedback and sorry about the fever - speedy recovery!

Here is my example that uses car lease calculations, I'm all for avoiding augments :), but what you suggest fits better for this design:

export const SUM = {
  augment: L.augment({extra:({CarPrice, Downpayment, CostAddedtoLease, Term, HST, InterestRate, ResidualValuePercent}) =>{
    const CapCost = CarPrice - Downpayment + CostAddedtoLease
    const ResidualValueDollar = CarPrice * ResidualValuePercent / 100
    const Depreciation = (CapCost - ResidualValueDollar) / Term
    const Finance = (CapCost + ResidualValueDollar) * (InterestRate/2400)
    const MonthlyPayment = Depreciation + Finance
    const TotalMonthlyPayment = MonthlyPayment + (MonthlyPayment * (HST/100))   

    return {CapCost, ResidualValueDollar, Depreciation, Finance, MonthlyPayment, TotalMonthlyPayment}
  }}),  
  CarPrice: "CarPrice",
  ScenarioName: "ScenarioName",
  id: "id",         
  Downpayment: "Downpayment",
  CostAddedtoLease: "CostAddedtoLease",  
  ResidualValuePercent: "ResidualValuePercent",  
  Term: "Term",
  HST: "HST",
  InterestRate: "InterestRate",
  CapCost: R.prop("CapCost"),
  Depreciation: R.prop("Depreciation"),
  Finance: R.prop("Finance"),
  MonthlyPayment: R.prop("MonthlyPayment"),
  ResidualValueDollar: R.prop("ResidualValueDollar"),
  TotalMonthlyPayment: R.prop("TotalMonthlyPayment"),    
  CreateDate: "CreateDate",
  ChangeDate: "ChangeDate" 
}

Also how the extra property would be referenced from the control - like this K(item, M.SUM.extra.CapCost)

Really appreciate the framework and your help!

from partial.lenses.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.