Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restartable compromises symbol-observable interop #67

Closed
xtianjohns opened this issue Dec 15, 2017 · 3 comments
Closed

Restartable compromises symbol-observable interop #67

xtianjohns opened this issue Dec 15, 2017 · 3 comments

Comments

@xtianjohns
Copy link
Collaborator

When iterating on source properties in restartable, symbol-observable support is compromised.

This means the following code won't work:

import { from } from 'my-stream-library';

export function component( sources ) {
  /* assuming that the DOM driver was wrapped */
  const source$ = sources.DOM.select( '#foo' ).events( 'click' );
  return {
    anything: from( source$ ), // this throws
  };
}

The error is specifically that source$ does not have a property from symbol-observable that is added by xstream for interop with different stream libraries.

I think this is related to #55, but is slightly different since it isn't about a problem with driver methods/props, but with source/sink props.

To test that this can work, just wrap a driver (DOM sources from @cycle/dom are an acceptable candidate), and test that the property exists.

import $$observable from 'symbol-observable';
export function component( sources ) {
  /* assuming that the DOM driver was wrapped */
  const source$ = sources.DOM.select( '#foo' ).events( 'click' );
  console.info( source$[ $$observable ] );
  /* ... */
}

Also, symbol-observable is just one case, this would be true of all properties that relied on symbols or supported custom features on streams. But it's just an example of the broader problem.

Happy to help work on this @Widdershin, and submit the PR, but it looks like you may have started some work already as part of the Cycle Unified milestone? Let me know how I can help, and I'll get on it.

@xtianjohns
Copy link
Collaborator Author

I have a fix for this working locally for my use-case, but it relies on some newer ES functionality. In my specific case we're looking for interop with Symbols, which should only exist in ES2015 anyway, so I'd be okay with a polyfill for some of this functionality.

Without a polyfill, the tests relying on the behavior break. Here's the gist of my potential solution (not the whole thing). Before I commit and submit a PR, is there any more discussion that we should have on this?

function keys (obj) {
  const _keys = [];

  for (const prop in obj) {
    _keys.push(prop);
  }

  // get all of the symbols on the object
  for(const prop of Object.getOwnPropertySymbols(obj) ) { 
    _keys.push(prop);
  }

  // get all of the symbols on the prototype
  for(const prop of Object.getOwnPropertySymbols(Object.getPrototypeOf(obj) || {}) ) {
    _keys.push(prop);
  }

  return _keys;
}

Would appreciate your thoughts when you have time @Widdershin. Also note that breakages don't affect anything in the monorepo, but they will affect CycleJS flavors that use restartable out of the box (like one-fits-all). CC @jvanbruegge

@Widdershin
Copy link
Owner

Widdershin commented Dec 16, 2017 via email

xtianjohns added a commit to xtianjohns/cycle-restart that referenced this issue Dec 22, 2017
Ensure properties that are symbols are included in streams wrapped by
cycle-restart.

Many stream libraries are using symbols to standardize interoperability
between one another. When transforming streams as part of cycle-restart,
it is important to retain all behavior that is present on the stream or
on its prototype.

This change includes a shim for Object.getOwnPropertySymbols, which is
used to retrieve all symbols from an object.

Resolve Widdershin#67.
xtianjohns added a commit to xtianjohns/cycle-restart that referenced this issue Dec 22, 2017
Test the preservation of symbol properties when driver functions are
wrapped by restartable.

Note, these tests don't verify that prototype properties on xstream are
preserved because it would require adding a dependency on
symbol-observable. Additionally, the specific bug being tested is only
introduced we sinks are recreated property-by-property. This doesn't
happen with xstream sinks.

Related to Widdershin#67.
@xtianjohns
Copy link
Collaborator Author

PR is up @Widdershin, I included a shim. Open to feedback - I tried to keep the diff small.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants