Created
March 24, 2018 12:41
-
-
Save sean-nicholas/224f26944a0e3ed9439daf4115687ac4 to your computer and use it in GitHub Desktop.
feathers-reactive with Angular Universal - rx universal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Observable } from 'rxjs/Observable' | |
| export function rxUniversal(options = {}) { | |
| const mixin = function (service) { | |
| const app = this | |
| const serviceMixin = { | |
| watch(watchOptions = {}) { | |
| const methods = {} | |
| app.methods.forEach(method => { | |
| if (typeof service[method] === 'function') { | |
| methods[method] = (...args) => { | |
| const serviceMethod = service[method].bind(service) | |
| return Observable.from(serviceMethod(...args)) | |
| } | |
| } | |
| }) | |
| return methods | |
| } | |
| } | |
| // get the extended service object | |
| const newService = service.mixin(serviceMixin) | |
| // workaround for Firefox | |
| // FF defines Object.prototype.watch(), so uberproto doesn't recognize the mixin's .watch() | |
| // see https://github.com/feathersjs-ecosystem/feathers-reactive/issues/67 | |
| if ((Object.prototype as any).watch && (Object.prototype as any).watch === newService.watch) { | |
| newService.watch = serviceMixin.watch | |
| } | |
| } | |
| return function (app) { | |
| app.mixins.push(mixin) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment