Code Monkey home page Code Monkey logo

Comments (9)

fiatjaf avatar fiatjaf commented on May 19, 2024

It is starting to feel that I should create a fork of this repository just to implement my thing, but I don't like that idea. However, it is not clear how should I do it even in a fork. Please help!

from observer-util.

solkimicreb avatar solkimicreb commented on May 19, 2024

i am checking it. it might take some time for me to fully grasp it though 😉

from observer-util.

solkimicreb avatar solkimicreb commented on May 19, 2024

If I understand correctly you would like to do something like this:

import xs from 'observable-xstream'

const observableStream = xs.periodic(1000)
  .filter(i => i % 2 === 0)
  .map(i => i * i)
  .endWhen(xs.periodic(5000).take(1))

// auto logs a number that increments every second from 1 to 5
observe(() => console.log(observableStream.value))

Is this roughly correct or am I totally off track?

from observer-util.

fiatjaf avatar fiatjaf commented on May 19, 2024

Yes, that's basically it. Thank you.

However, I was implementing it in a transparent way, without the need of the .value property, by assigning streams to an object.

import xs from 'xstream' 
import observableStreams from 'observables-xstream' 

const stream = xs.periodic(1000)
  .filter(i => i % 2 === 0)
  .map(i => i * i)
  .endWhen(xs.periodic(5000).take(1))

var state = observableStreams({
  number: stream
})

// auto logs a number that increments every second from 1 to 5
observe(() => console.log(state.number))

Looking now, I think that all my problems arise from that implementation and that your 'observable-xstream' would be much easier to implement.

from observer-util.

fiatjaf avatar fiatjaf commented on May 19, 2024

It gets worse when I remember that the values emitted by the stream may be objects or collections, even with others streams as values, and those should be observables too, just like the top object.

from observer-util.

solkimicreb avatar solkimicreb commented on May 19, 2024

No worries, nested observable construction is automatic in nx-js observer util. I have to work now but I will get back to this in the afternoon. I think it will be much simpler than it seems like (;

from observer-util.

fiatjaf avatar fiatjaf commented on May 19, 2024

Nested observables are automatic, but not in my special case if it requires a special function to turn streams into observable values.

I'm counting on you to give me an awesome magical solution here :P

from observer-util.

solkimicreb avatar solkimicreb commented on May 19, 2024

sorry, i was busy during the weekend, i don't want to ruin your motivation/inspiration for this. is your fork public?

from observer-util.

fiatjaf avatar fiatjaf commented on May 19, 2024

You're not ruining anything. I don't know if my approach is solid and you have no responsibility for my incompetence.

I've just found https://github.com/calmm-js/karet, that does something similar of what I wanted to do, without passing through the process of converting things to observables, they just make the component somehow listen to emitted values on the stream. The point is that I can't understand what they're doing there, much less than I could at observer-util or react-easy-state, it's pure magic.

Anyway, what do you said you thought would be "much simpler"? You're talking about adding new features to this repository (for "plugging in"), or writing a wrapper around it?


My "fork" is currently a mess of files in my local disk, but the only relevant changes are

  • I've added a global WeakMap named streamResults for caching the "current" stream values.
  • On object initialization, for each property, and whenever a new property is added to an observable I call
function handleStream (stream) {
  if (stream && typeof stream.subscribe === 'function') {
    stream.subscribe({
      next (v) {
        streamResults.set(stream, v)
      },
      error (e) {
        streamResults.set(stream, e)
      }
    })
  }
}
  • on the common get handler for objects, right after var result = Reflect.get(target, key, receiver) I do
  if (result.subscribe) {
    result = streamResults.get(result)
  }

from observer-util.

Related Issues (20)

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.