Coder Social home page Coder Social logo

observ's People

Contributors

berendkleinhaneveld avatar korijn avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

observ's Issues

More detailed watch callback

It would be useful to have more detailed info for watch callbacks on collections to have a better understanding what has changed. Currently, the callback for arrays yields new and old objects but they are usually the same because they point to the same object. I think this is also the case for dicts.

Especially for dicts it would be beneficial to know for which keys the values have changed, which key/value pairs have been added and which key/value pairs have been removed. For arrays the same applies, but then you would expect indices of course.

Thread safety

We need to use a threading.RLock to ensure thread safety when working with the globals:

observ/observ/dep.py

Lines 9 to 10 in b3c0e62

class Dep:
stack: List["Watcher"] = [] # noqa: F821

# Create a global proxy collection
proxy_db = ProxyDb()

I'm wondering what thread safety means in the context of observ...

Public API

Need to define three methods:

  • state = make_reactive(data)
  • computed_prop = cached(prop_func)
  • watch(state['prop'], callback)

Proxying

It should be (relatively) easy to also add readonly(state) which would provide a proxy onto an observable that throws an error on any write operation.

Wrap __hash__?

When looking at EXCLUDED in the test suite for observable collections, maybe __hash__ needs to be implemented as a reader too? I'm not entirely sure.

The other attributes don't need to be wrapped, __hash__ is the only questionable item in the list.

Benchmarks

Would be nice to have a benchmark setup so that we can make informed decisions on performance.

We could leverage pytest-benchmark together with github-action-benchmark.
And naturally we would need to have some proper functions to run as benchmark.

Minimize deps

E.g. dict.copy causes depend to be called for the dict dep and all its keydeps, where only the dict dep would be sufficient.

This mostly matters in eager mode but in general it would shave off some redundant function calls

Is it possible to watch all variables that are being observed?

from observ import computed, observe, watch


doc_state = observe({"selected": False, "pos": (0, 0)})

def my_callback(old, new):
    print(old, new)

w = watch(lambda: doc_state["selected"], callback=my_callback)

doc_state["selected"] = True
doc_state["selected"] = False

For example, in the code above, is it possible to watch both the selected and pos var without declaring a new watch statement?

I guess I am trying to understand how multiple variables can be watched. My understanding is that something like the following is needed:

from observ import computed, observe, watch


doc_state = observe({"selected": False, "pos": (0, 0)})

def my_selected_callback(old, new):
    print("selected: ", old, new)

def my_pos_callback(old, new):
    print("pos: ", old, new)

# setup the watchers
w1 = watch(lambda: doc_state["selected"], callback=my_selected_callback)
w2 = watch(lambda: doc_state["pos"], callback=my_pos_callback)

# do some stuff...

# set the sate
doc_state["selected"] = True
doc_state["selected"] = False

doc_state["pos"] = (3, 5)

Callback scheduling

Should they be buffered? Should I provide event loop integration for various libs (i.e. asyncio, qt, etc)?

Dont invalidate on write when value doesnt change

Not sure if this is really worthwhile, there's a performance tradeoff I guess. It depends if the dependency tracking is more expensive or if the computed prop function is more expensive.

It's probably the latter, so that would make the resolution of this issue worthwhile.

Will have to see how I can generalize the equality test over all the WRITER and KEYWRITER methods we wrap.

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.