選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

140 行
4.3 KiB

  1. /** @license
  2. * Copyright 2016 - present The Material Motion Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy
  6. * of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations
  14. * under the License.
  15. */
  16. "use strict";
  17. /** @license for symbol-observable:
  18. * The MIT License (MIT)
  19. *
  20. * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
  21. * Copyright (c) Ben Lesh <ben@benlesh.com>
  22. *
  23. * Permission is hereby granted, free of charge, to any person obtaining a copy
  24. * of this software and associated documentation files (the "Software"), to deal
  25. * in the Software without restriction, including without limitation the rights
  26. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  27. * copies of the Software, and to permit persons to whom the Software is
  28. * furnished to do so, subject to the following conditions:
  29. *
  30. * The above copyright notice and this permission notice shall be included in
  31. * all copies or substantial portions of the Software.
  32. *
  33. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  34. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  35. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  36. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  37. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  38. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  39. * THE SOFTWARE.
  40. */
  41. var $observable = (
  42. () => {
  43. var root;
  44. if (typeof self !== 'undefined') {
  45. root = self;
  46. } else if (typeof window !== 'undefined') {
  47. root = window;
  48. } else if (typeof global !== 'undefined') {
  49. root = global;
  50. } else if (typeof module !== 'undefined') {
  51. root = module;
  52. } else {
  53. root = Function('return this')();
  54. }
  55. var result;
  56. var Symbol = root.Symbol;
  57. if (typeof Symbol === 'function') {
  58. if (Symbol.observable) {
  59. result = Symbol.observable;
  60. } else {
  61. result = Symbol('observable');
  62. Symbol.observable = result;
  63. }
  64. } else {
  65. result = '@@observable';
  66. }
  67. return result;
  68. }
  69. )();
  70. /**
  71. * Observable is a standard interface that's useful for modeling multiple,
  72. * asynchronous events.
  73. *
  74. * IndefiniteObservable is a minimalist implementation of a subset of the TC39
  75. * Observable proposal. It is indefinite because it will never call `complete`
  76. * or `error` on the provided observer.
  77. */
  78. class IndefiniteObservable {
  79. /**
  80. * The provided function should receive an observer and connect that
  81. * observer's `next` method to an event source (for instance,
  82. * `element.addEventListener('click', observer.next)`).
  83. *
  84. * It must return a function that will disconnect the observer from the event
  85. * source.
  86. */
  87. constructor(connect) {
  88. this._connect = connect;
  89. }
  90. /**
  91. * `subscribe` uses the function supplied to the constructor to connect an
  92. * observer to an event source. Each observer is connected independently:
  93. * each call to `subscribe` calls `connect` with the new observer.
  94. *
  95. * To disconnect the observer from the event source, call `unsubscribe` on the
  96. * returned subscription.
  97. *
  98. * Note: `subscribe` accepts either a function or an object with a
  99. * next method.
  100. */
  101. subscribe(observerOrNext) {
  102. const observer = _wrapWithObserver(observerOrNext);
  103. let disconnect = this._connect(observer);
  104. return {
  105. unsubscribe() {
  106. if (disconnect) {
  107. disconnect();
  108. disconnect = undefined;
  109. }
  110. }
  111. };
  112. }
  113. /**
  114. * Tells other libraries that know about observables that we are one.
  115. *
  116. * https://github.com/tc39/proposal-observable#observable
  117. */
  118. [$observable]() {
  119. return this;
  120. }
  121. }
  122. function _wrapWithObserver(listener) {
  123. if (typeof listener === 'function') {
  124. return {
  125. next: listener
  126. };
  127. }
  128. else {
  129. return listener;
  130. }
  131. }