Comments (2)
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.
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)
- Error with react native HOT 3
- Add Node compatible `L.querystring` isomorphism
- Optic doesn't support Symbol. HOT 8
- Consider adding more parsing + stringifying combinators or a separate library
- Consider adding support for Maps and Sets
- Consider adding support for splitting an object into disjoint subsets of keys HOT 1
- Change `L.removable` Take a Predicate? HOT 3
- Consider adding `disperse` operation and `partsOf` lens constructor
- Isomorphism in L.array called with undefined HOT 2
- Index isomorphism HOT 5
- Great Work 👍 Thank you (No issue) HOT 5
- Dealing with exceptions?
- I'd like to L.traverse an object HOT 4
- Usage with JSON Patching? HOT 3
- Add example exercise answers to wiki? HOT 4
- Nested matches for L.satisfying HOT 2
- Branches Does not preserve order HOT 2
- Modifying a nested data structure? HOT 12
- `L.get` has unexpected behavior HOT 2
- Does not works with Modules object
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from partial.lenses.