MCPcopy Create free account
hub / github.com/adobe/react-spectrum / reducer

Function reducer

packages/@react-spectrum/s2/src/ImageCoordinator.tsx:64–119  ·  view source on GitHub ↗
(state: State, action: Action)

Source from the content-addressed store, hash-verified

62 | {type: 'timeout'};
63
64function reducer(state: State, action: Action): State {
65 switch (action.type) {
66 case 'register': {
67 if (state.loaded.get(action.url) !== false) {
68 let loaded = new Map(state.loaded);
69 loaded.set(action.url, false);
70 return {
71 loadedAll: false,
72 // If we had previously loaded all items, then reset the timed out state
73 // since this is the first item of a new batch.
74 timedOut: state.loadedAll ? false : state.timedOut,
75 loadStartTime: state.loadedAll ? Date.now() : state.loadStartTime,
76 loaded
77 };
78 }
79 return state;
80 }
81 case 'unregister': {
82 if (state.loaded.has(action.url)) {
83 let loaded = new Map(state.loaded);
84 loaded.delete(action.url);
85 return {
86 loadedAll: isAllLoaded(loaded),
87 timedOut: state.timedOut,
88 loadStartTime: state.loadStartTime,
89 loaded
90 };
91 }
92 return state;
93 }
94 case 'load': {
95 if (state.loaded.get(action.url) === false) {
96 let loaded = new Map(state.loaded);
97 loaded.set(action.url, true);
98 return {
99 loadedAll: isAllLoaded(loaded),
100 timedOut: state.timedOut,
101 loadStartTime: state.loadStartTime,
102 loaded
103 };
104 }
105 return state;
106 }
107 case 'timeout': {
108 if (!state.loadedAll && !state.timedOut) {
109 return {
110 ...state,
111 timedOut: true
112 };
113 }
114 return state;
115 }
116 default:
117 return state;
118 }
119}
120
121function isAllLoaded(loaded: Map<string, boolean>) {

Callers

nothing calls this directly

Calls 4

isAllLoadedFunction · 0.85
deleteMethod · 0.80
hasMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected