MCPcopy Create free account
hub / github.com/microsoft/SandDance / getDescriptorForAsyncProp

Function getDescriptorForAsyncProp

docs/tests/v2/es6/js/sanddance.js:43012–43053  ·  view source on GitHub ↗
(name)

Source from the content-addressed store, hash-verified

43010
43011
43012function getDescriptorForAsyncProp(name) {
43013 return {
43014 configurable: false,
43015 enumerable: true,
43016 // Save the provided value for async props in a special map
43017 set: function set(newValue) {
43018 if (typeof newValue === 'string' || newValue instanceof Promise) {
43019 this._asyncPropOriginalValues[name] = newValue;
43020 } else {
43021 this._asyncPropResolvedValues[name] = newValue;
43022 }
43023 },
43024 // Only the component's state knows the true value of async prop
43025 get: function get() {
43026 if (this._asyncPropResolvedValues) {
43027 // Prop value isn't async, so just return it
43028 if (name in this._asyncPropResolvedValues) {
43029 var value = this._asyncPropResolvedValues[name]; // Special handling - components expect null `data` prop expects to be replaced with `[]`
43030
43031 if (name === 'data') {
43032 return value || this._asyncPropDefaultValues[name];
43033 }
43034
43035 return value;
43036 }
43037
43038 if (name in this._asyncPropOriginalValues) {
43039 // It's an async prop value: look into component state
43040 var state = this._component && this._component.internalState;
43041
43042 if (state && state.hasAsyncProp(name)) {
43043 return state.getAsyncProp(name);
43044 }
43045 }
43046 } // the prop is not supplied, or
43047 // component not yet initialized/matched, return the component's default value for the prop
43048
43049
43050 return this._asyncPropDefaultValues[name];
43051 }
43052 };
43053} // HELPER METHODS
43054
43055
43056function hasOwnProperty(object, prop) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected