Skip to content

Commit

Permalink
Merge pull request #143 from knockout/bmh/observable-symbol-polyfill
Browse files Browse the repository at this point in the history
observable) add polyfill for Symbol.observable
  • Loading branch information
brianmhunt authored Jul 10, 2021
2 parents 2b45b3f + e36b60e commit afaa804
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/observable/spec/subscribableBehaviors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ describe('Subscribable', function () {
expect(isSubscribable(null)).toEqual(false)
})

it('creates/has a Symbol.observable', () => {
const sub = new subscribable()
expect(Symbol.observable).toEqual(Symbol.for('@tko/Symbol.observable'))
expect(sub[Symbol.observable]()).toBe(sub)
})

it('Should be able to notify subscribers', function () {
var instance = new subscribable()
var notifiedValue
Expand Down
5 changes: 5 additions & 0 deletions packages/observable/src/subscribable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export { isSubscribable } from './subscribableSymbol'
// subscribed.
export const LATEST_VALUE = Symbol('Knockout latest value')


if (!Symbol.observable) {
Symbol.observable = Symbol.for('@tko/Symbol.observable')
}

export function subscribable () {
Object.setPrototypeOf(this, ko_subscribable_fn)
ko_subscribable_fn.init(this)
Expand Down

0 comments on commit afaa804

Please sign in to comment.