Platform-Node.st 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. Smalltalk createPackage: 'Platform-Node'!
  2. (Smalltalk packageAt: 'Platform-Node' ifAbsent: [ self error: 'Package not created: Platform-Node' ]) imports: {'amber/core/Platform-Services'}!
  3. Object subclass: #NodePlatform
  4. slots: {}
  5. package: 'Platform-Node'!
  6. !NodePlatform commentStamp!
  7. I am `Platform` service implementation for node-like environment.!
  8. !NodePlatform methodsFor: 'accessing'!
  9. globals
  10. ^ global
  11. ! !
  12. !NodePlatform methodsFor: 'public API'!
  13. fetch: aStringOrObject
  14. ^ self globals at: #fetch
  15. ifPresent: [ :fetch | fetch value: aStringOrObject ]
  16. ifAbsent: [ Promise signal: 'fetch not available.' ]
  17. !
  18. fetchUrl: aString options: anObject
  19. ^ self globals at: #fetch
  20. ifPresent: [ :fetch | fetch value: aString value: anObject ]
  21. ifAbsent: [ Promise signal: 'fetch not available.' ]
  22. !
  23. newXhr
  24. XMLHttpRequest
  25. ifNotNil: [ ^ XMLHttpRequest new ]
  26. ifNil: [ self error: 'XMLHttpRequest not available.' ]
  27. ! !
  28. !NodePlatform class methodsFor: 'testing'!
  29. initialize
  30. self isFeasible ifTrue: [ Platform registerIfNone: self new ]
  31. !
  32. isFeasible
  33. <inlineJS: 'return typeof process !!== "undefined" && process && process.versions && process.versions.node !!= null'>
  34. ! !