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

Implement can-symbol #1

Closed
justinbmeyer opened this issue Mar 3, 2017 · 7 comments
Closed

Implement can-symbol #1

justinbmeyer opened this issue Mar 3, 2017 · 7 comments

Comments

@justinbmeyer
Copy link
Contributor

justinbmeyer commented Mar 3, 2017

Related issues:

Symbols (and corresponding expected value)

All CanJS symbols will be prefixed with can.

Type detection:

  • isMapLike Boolean - Item has values at keys
  • isListLike Boolean - Item has values at enumerated keys
  • isValueLike Boolean - Item has a single value
  • isFunctionLike Boolean - Item can be called with arguments
  • isConstructorLike Boolean

Shape detection:

  • getOwnKeyNames - How to get a list of all the keys on this object. Returns an iterator.
  • keyDescriptor - Returns information about this key. Probably info beyond Object.getPropertyDescriptor would normally provide.
  • getValueDescriptor - Returns information about the value contained in this observable.
  • iterator - Same as iterator
  • proto

Get / Set:

  • getValue
  • setValue
  • getKeyValue
  • setKeyValue

Call:

  • call
  • apply
  • new

Observe:

  • onValue cb() -> valueIndex
  • offValue cb()
  • onKeyValue cb() -> valueIndex
  • offKeyValue cb() -> valueIndex
  • keyDependencies - The observable dependencies of a property in a map-like structure.
  • valueDependencies - The observable dependencies of a value-like structure.

Methods

.for(key)

var canSymbol = require("can-symbol");

// env supports Symbols:
canSymbol('bar') //-> Symbol('bar')

// env doesn't support Symbols
// return can-symbol-bar to avoid conflicts
canSymbol('bar') //-> 'can-symbol-bar'

.keyFor( description )

Questions

  • How would promises and streams work?
@matthewp
Copy link

matthewp commented Mar 3, 2017

Symbol has two APIs: Symbol('foo') !== Symbol('foo') and Symbol.for('foo') === Symbol.for('foo'). The latter is saved in an internal map so that each call gets the same symbol back. Will can-symbol have both of these as well?

@justinbmeyer
Copy link
Contributor Author

justinbmeyer commented Mar 3, 2017

@matthewp These are really only for "well known" symbols. They are there primarily for can-operate to use. It's to house "statefulness". There can be only one version of these symbols for CanJS to work.

tldr; We only need Symbol.for.

@matthewp
Copy link

matthewp commented Mar 3, 2017

We need private Symbols in can-zone.

@justinbmeyer
Copy link
Contributor Author

Why?

@matthewp
Copy link

matthewp commented Mar 3, 2017

They are semi-private properties. They are unenumerable and can only be touched by outside code if they use Object.getOwnPropertySymbols and even then you can't get the string key used to make that symbol (so effectively you can't tell what a Symbol represents).

@matthewp
Copy link

matthewp commented Mar 3, 2017

One place where we use them is here: https://github.com/canjs/can-zone/blob/master/lib/zones/xhr.js#L21 to detect of an XHR request should come from the XHR_CACHE that is returned by server rendering.

@justinbmeyer
Copy link
Contributor Author

This is going to change to a symbol polyfill that also includes the above registered symbols.

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