Giter Club home page Giter Club logo

oby's People

Contributors

brandonbritton avatar fabiospampinato avatar thesherwood avatar titobouzout 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  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  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  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

oby's Issues

Question: Lazy Effect?

Is it possible for an effect to not trigger initially?

const test = $(false)

$.effect(() => {
    console.log('update', test())
})

SetTimeout(() => test(true), 100)

would log test two times.
It would be nice if we could have a flag to "not trigger on effect creation", and monitor only future changes.

Or am I blind and there is a config value that can make that possible already?

Observable API

Hi Fabio,

While voby is still 0.x, I'd like to suggest a change to the Observable API.

In a nutshell, I believe overloading is more or less "bad for everything".

The current API is triple overloaded:

type Observable<T> = {
  (): T,
  ( value: T ): T,
  ( fn: ( value: T ) => T ): T
};

It's misleading. An observable is not a function - it's actually an object with 3 methods.

Modeling it as an overloaded function favors writing code fast and sacrifices readability - producing code where every method call is ambiguous, with $value(...) essentially saying "do something with ...", requiring (A) the programmer to parse to ... expression and figure out what it does, and (B) the run-time to dynamically type-check values.

What I would propose instead:

type Observable<T> = {
  (): T,
  set( value: T ): T,
  update( fn: ( value: T ) => T ): T
};

Words provide semantics, making for more readable code:

const $count = $(0);

const increment = () => $count.update(prev => prev + 1);
const decrement = () => $count.update(prev => prev - 1);
const reset = () => $count.set(0);

I know this is somewhat opinionated, perhaps bordering on bikeshedding territory, and it's a big breaking change. But it might eliminate some (however slight) run-time/complexity overhead, and avoids beginner questions/mistakes such as "how to put a function in an Observable?".

Admittedly, this suggestion is mostly opinionated. It probably comes mostly down to personal preference. Although I think, objectively, seeing the words update or set where those operations take place seems pretty reasonable - overloading does not help readability.

Whether you think writing or reading is more important of course does come down to opinion, but in my experience, code is read more times (by more persons) than written.

Just something to think about and consider. ๐Ÿ˜‡

Exclude tsconfig.json from npm dist

I have been using TypeScript 5.x in a new project and I have noticed that when I press F8 to track errors, VSCode often jumps to the node_modules/oby/tsconfig.json file and prompts me that it cannot find the tsex/tsconfig.json file. This also causes a lot of import statements in the node_modules/oby/src directory to be marked as red errors when I browse through the code. I hope that these tsconfig.json files can be excluded when the npm package is released next time. I also hope that the same setting can be adopted in voby.

Circular References

Just an FYI - I'm seeing a (!) Circular dependencies warning when using this lib, mainly around "context.js" by the look of it.

Nice work, though!

Infinite recursion with arrays

@fabiospampinato

I've been running into a lot of difficult-to-debug issues around infinite loops involving arrays and circular references. Here's a sandbox with a sample of what I'm talking about:

https://codesandbox.io/s/voby-demo-store-counter-forked-r225g4?file=/src/index.tsx
(click the + a couple times and the app will hang)

This has been a bit difficult in my app because Solid handles these circular references in arrays just fine and I have data of a similar shape cropping up in numerous places in my app. So this looks to me like a bug, but what do you think? Are these cases something that voby/oby should handle? Or does there just need to be a big warning sign in the readme?

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.