Code Monkey home page Code Monkey logo

lychee's People

Contributors

imbeerus avatar miha-x64 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  avatar  avatar  avatar  avatar

lychee's Issues

STM-like behaviour

While committing a transaction, properties should update their values at most once, delivering the latest, consistent changes.

CASing boxed primitives

val prop = propertyOf(127)
prop.compareAndSet(127, 128) // true
prop.compareAndSet(128, 127) // false

References for boxed 128s differ.

On unsuccessful CAS, a property may internally check whether compared values are boxed primitives which are equal, and repeat attempt.

FAQ

How this works.
Comparison to fx.Property, Android.util.Property, io.reactivex.BehaviorSubject.
No binary compatibility? Inline, flyweights.
Automatic disposal. When properties are eligible for GC.

SQL (Android-SQLite, JDBC) support

  • Prototype, SQLite, observability
  • SQL templates
  • Create trigger-based observability which will work for external INSERT/UPDATE/DELETE statements and for multi-node applications with a shared database
  • Support mutating SQL templates
  • deprecate DAOs and Records

Animation support

When a propertyOf(some colour) changes its value, makes sense to add a way of animating it smoothly on bound views.

Easy way to unbind (dispose subscription)

During binding, one passes a category, e. g. DATA, UI, DEFAULT. Then it becomes easy to dispose some category of binding, even automatically, e. g. prop.unsubscribeAll(UI).

Change listener may want to do some clean-up when it gets unsubscribed.
Its type, (old: T, new: T) -> Unit, may be replaced with something like

interface PropertyChangeListener<in T> : (old: T, new: T) -> Unit {
    fun unsubscribed()
}

Convenience constructor should be added:

inline fun <T> PropertyChangeListener(crossinline onChange: (old: T, new: T) -> Unit) = ...

PropertyChangeListener name looks too long, suggestions are appreciated.

Emulate pattern-matching

CompletableFuture

It may be called Task, this won't interfere with most known implementations.

Anatomy of a Task.
type State = Initial | Executing | Failed | Canceled | Success | Terminally failed

Executing may have retry: Int which is 0 for first time and increments with next retries.
Failed: the task still may be retried.
Canceled: All subscribers were unsubscribed. Restarts when gets observed.
Terminally failed: number of retries exceeded.

isTerminal:
task.filter { it.isTerminal } may have type State = Success | Terminally failed.

Retry may be triggered explicitly or?..

Schedulers

Add a way to subscribe on a certain thread. For mapper properties, add a way to compute on another thread. Along with #15, this may work like

// list: DiffProperty<List<Item>, SomeDiffMeta>
list.mapWithDiff(
    computeOn = someBackgroundScheduler,
    notifyOn = mainThread
) { items, meta ->
    items to DiffUtil.doStuff(items, meta)
}

inline class PropertyOrValue<T>

A zero-cost wrapper which acts like Property<T> | T.

// pseudokode, won't kompile
inline class PropertyOrValue<T> {
    private val _value: Any? // = Property<T> | T
    constructor(value: T) {
        this._value = // guard against the (rare) case when value is also a property:
            if (value is Property<*>) immutablePropertyOf(value)
            else value
    }
    constructor(property: Property<T>) {
        this._value = property
    }
    val value: T
        get() = (if (_value is Property<*>) _value.value else _value) as T
    // TODO: addChangeListener(On), removeChangeListener
}

Use-cases:

  • universal [library] components which accept some Properties may accept PropertyOfValue instead, allowing caller to avoid wrapping value into ImmutableProperty
  • Android resources: (typedValue.changingConfigurations & activityInfo.configChanges) == 0 implies Value, else Property (not sure how popular this case is, taking into account that resources are good at storing strings, but other resource types โ€” animations and animators, drawables, colours and colour state lists, layouts, menus, styles, fonts, scalars and scalar arrays โ€” are mostly useless)

New extensions

mutableProp.casValue(expect, new): Boolean
mutableProp.updateValue { ... } // using CAS, inline

booleanMutableProp.takeEvery(true) {
    "value was switched to true but we've switched back to false and called this code"
} // using CAS to switch
booleanMutableProp.set(): Boolean
booleanMutableProp.reset(): Boolean

Also, group extensions better.

Unsubscribe instantly, defer nested update

Listeners are [A, B].

  1. A gets notified and removes B. B must not be notified then, even within this single iteration.
  2. A changes observable's value. Updates must be sequentially-consistent, e. g.
    • notify A
    • A wants to change value? we're notifying now, defer it
    • notify B
    • execute deferred change:
    • change value
    • notify A
    • notify B

Fix pom

pom.xml should have dependency on Kotlin

Concurrent bindTo + observedStateChanged

Thread 1 adds/removes first/last listener to such property causing observed state change and (un)subscription from/to sample property
Thread 2 binds the same property to another one causing re-subscription

deal with single-threaded and unconfined subscriptions

Currently notification occurs on the thread where value has been changed. It's OK for single-threadd properties, but may be really sad for concurrent properties, especially when you don't know that a property is concurrent.
This behaviour should be consistent across implementations.

More extensible Persistence

Remove List, Enum, EnumSet support from PropertyIo; introduce interface Converter<T> { fun read(DataInput): T; fun write(DataInput, T) }; add List, Enum, EnumSet, ByteString support as extensions.

Maybe move this to another artifact.

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.