Code Monkey home page Code Monkey logo

dendriform's People

Contributors

dclarkeatlas avatar dxinteractive avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dendriform's Issues

Idea: LazyDeriver

New data type that can lazily derive, async, for heavy operations.

  • LazyDeriver can subscribe to dendriforms and other lazyderivers
  • its value returns a promise and accessing it kicks off the lazy derivation
  • each lazy derivation waits for all the lazyderivers it is subscribed to before doing its own computation
  • lazyderiver results are cached, and the cache is only cleared when any dendriform it is subscribed to changes, or when any lazyderiver it is subscribed to has its cache cleared
  • if a lazyderiver has its cache cleared but also has a currently active useValue() hook, it will kicks off its lazy derivation again
  • some option to say what the fallback value for the lazyderiver is, to be used by the useValue() hook - it may even want to pass through something that its subscribed to (e.g. image rendering that builds up over time) or keep its old value until the new one is done deriving.
  • some piece of state that says if derivation is in progress
const nameForm = new Dendriform('cool');
const ageForm = new Dendriform(12);

const picture = new LazyDeriver(async () => {
    coolCanvas.text('name', nameForm.value);
    coolCanvas.text('age', ageForm.value);
    return await coolCanvas.render();
}, [nameForm, ageForm]);

button.onClick(() => {
    document.appendChild(await picture.value);
});

// react
function Compy() {
    const picture = useLazyDeriver(async () => {
        coolCanvas.text('name', nameForm.value);
        coolCanvas.text('age', ageForm.value);
        return await coolCanvas.render();
    }, [nameForm, ageForm]);

    const pictureInverted = useLazyDeriver(async () => {
        return await picture.invert();
    }, [picture]);

    return <div>{pictureInverted.useValue()}</div>;
}

Idea: blockable changes

Be able to make forms that test potential changes with a function, and do not accept changes if that test fails. Also don't allow changes to go through if derived functions fail too. Might involve an internal revert function that can be called on all derived things.

This could allow for a generalised "collection of items whose ids refer to specific other items lifespans" construct

Async buffering can cause state reverts in rare circumstances

Async buffering is an API nicety, but the timing issues it causes aren't worth the hassle.

Right now if two changes can squeeze in rapid succession before a setTimeout(..., 0) can fire, then dendriform may push out an update that is stale compared to any state hooks that are tracking the same data in real time. This isn't the worst thing but can cause unavoidable cursor jumping if values are bound onto text inputs, and maybe worse.

Proposed solution

  • Make .set() not async by removing the setTimeout()
  • Add a batch() and flush() methods, and If someone wants to call 2 set() in a row they must call batch() first and finish with flush(). In dev mode we can warn if 2 sets get called too fast (less than setImmediate), and if flush isn't called fast enough (more than setImmediate)
  • Confirm all the deriving still works

Idea: set() meta

It can be useful for a set to pass along additional information in a set() so that onChange handlers can conditionally behave in a different way.

.useValue() usage can be much cleaner if it returns only the value

Instead of

const [value, setValue] = form.useValue();

it will be cleaner in most cases to have

const value = form.useValue();
// to set, call form.set();

because it avoids going form.useValue()[0] to do one-liners, reduces the API size (setValue and form.set are identical), and reduce confusion (setValue doesnt need to be used via a hook, but value does in order to receive updates)

Idea: readonly forms

Add something like form.readonly() that returns the same form but where .set() is disabled. This'll allow the observable abilities of forms to be spread around an app while also being able to whitelist where the forms value can be updated from.

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.