Code Monkey home page Code Monkey logo

sunrise's People

Contributors

denistakeda avatar evxn avatar marc136 avatar pabra avatar vooord avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sunrise's Issues

test types

We should probably add tsd to tests to ensure correct types.

Should `formula` always return a `Cell` instead of `Value`?

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 if val === 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 is T or in this this case T | null but null is already "eliminated" 2 lines above with val ? typeof renderFunction === 'function'....

The issue is that renderIf accepts cell as Value<T | null>. And Value is type Value<T> = T | Cell<T>. And since map became generic to accept Value<T> by itself.

If it's passed as Value TypeScript cannot decide whether it's Cell or just T. 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 a Cell in the following code. This leads to UnwrapCell type which has troubles handling UnwrapValue<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)
    }
}

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.