Skip to content

Commit afaa804

Browse files
authored
Merge pull request #143 from knockout/bmh/observable-symbol-polyfill
observable) add polyfill for Symbol.observable
2 parents 2b45b3f + e36b60e commit afaa804

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/observable/spec/subscribableBehaviors.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ describe('Subscribable', function () {
1717
expect(isSubscribable(null)).toEqual(false)
1818
})
1919

20+
it('creates/has a Symbol.observable', () => {
21+
const sub = new subscribable()
22+
expect(Symbol.observable).toEqual(Symbol.for('@tko/Symbol.observable'))
23+
expect(sub[Symbol.observable]()).toBe(sub)
24+
})
25+
2026
it('Should be able to notify subscribers', function () {
2127
var instance = new subscribable()
2228
var notifiedValue

packages/observable/src/subscribable.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export { isSubscribable } from './subscribableSymbol'
1414
// subscribed.
1515
export const LATEST_VALUE = Symbol('Knockout latest value')
1616

17+
18+
if (!Symbol.observable) {
19+
Symbol.observable = Symbol.for('@tko/Symbol.observable')
20+
}
21+
1722
export function subscribable () {
1823
Object.setPrototypeOf(this, ko_subscribable_fn)
1924
ko_subscribable_fn.init(this)

0 commit comments

Comments
 (0)