snapview / sunrise Goto Github PK
View Code? Open in Web Editor NEWThe reactive library for the spreadsheet driven development
License: MIT License
The reactive library for the spreadsheet driven development
License: MIT License
We should probably add tsd to tests to ensure correct types.
The following discussion popped during code review. I copy it here to continue.
renderFunction(val as T)
Michał:
pbraune Unsafe type casting
as T
. Maybe it is better to check ifval === null
? What if renderFunction actually expects null or other false value?
me:
Hi mklobukowski ,
null
is not the issue. Please open it in you IDE to investigate.
map
ensures, the argument passed to the function isT
or in this this caseT | null
butnull
is already "eliminated" 2 lines above withval ? typeof renderFunction === 'function'...
.The issue is that
renderIf
acceptscell
asValue<T | null>
. AndValue
istype Value<T> = T | Cell<T>
. And sincemap
became generic to acceptValue<T>
by itself.If it's passed as
Value
TypeScript cannot decide whether it'sCell
or justT
. Because I don't like type casting and beleave that TypeScript should be able to handle this case correctly, I created a separate branch to investigate this "issue".
There is a test case and some "mess" to solve it. Any help is welcome.
Michał:
pbraune I see. I took a look at sunrise and it is harder than I expected. Let's use
as T
for now.Btw, regarding the sunrise issue. I wonder if it isn't becoming too complicated just because we want to produce a
Value
instead of aCell
in the following code. This leads toUnwrapCell
type which has troubles handlingUnwrapValue<Value<T>>
because it distributes result over the union. I have found no solution to that. But it led me to the question: Is there a significant gain by not returning a cell when all inputs aren't cells? If we always returned FormulaCell, there wouldn't be a need for UnwrapValue type at all.export function formula<T>( fn: Function, ...sources: Value<unknown>[] ): FormulaCell<T> | T { if (sources.some(isCell)) { return new FormulaCell(fn, ...sources) } else { return fn(...sources) } }When returning FormulaCell always:
declare function myMap<V, R>(fn: (v: V) => R, input: Value<V>): FormulaCell<R>; { function callIf<T, U>( cellOrValue: Value<T>, cb: (arg: T) => U ): U | null { const res = myMap((value) => { if (value) { return cb(value) } return null }, cellOrValue) return deref(res) } }
If you add an DOM event handler to update a cell value whenever that event fires, it would be nice to remove that event handler (unsubscribe from that event) if the cell will be destroyed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.