8000 Errors · cerebral/cerebral Wiki · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
a-s-o edited this page Aug 16, 2015 · 3 revisions

Async action in not wrapped in an array

TypeError: actionFunc.apply is not a function

This error is caused when cerebral runs into an object where a function is expected in a signal's list of actions.

Example

// In the examples below fetchStaffList is an async action 
// Both of the signal declarations below will cause this error

cerebral.signal('staffListRequested', fetchStaffList, { success: [saveStaffToCache] })

cerebral.signal('staffListRouted', ...[
   checkStaffList, {
      stale: [fetchStaffList, { success: [saveStaffToCache] }],
      fresh: [],
      fetching: []
   }
]);

Fix

// Wrap async actions in an array

//                                    |-------------------------------------------------|
// Top level async actions            v                                                 v
cerebral.signal('staffListRequested', [ fetchStaffList, { success: [saveStaffToCache] } ])

cerebral.signal('staffListRouted', ...[
   checkStaffList, {
      
      // Nested async actions
      //       |-----------------------------------------------|
      //       v                                               v
      stale: [ [fetchStaffList, { success: [saveStaffToCache] }] ],
      fresh: [],
      fetching: []
   }
]);

Output path was called without arguments

There is no output of action "someAction" in signal "someSignal". It should have []

This error is thrown when an action calls an output path without any arguments

Example

// All the output paths are called without arguments,
// so they will all throw this error
function checkStaffList (input, store, output) {
   const list = store.get('staffList');
   if (list.isFetching) return output.fetching();
   if (list.lastUpdated > (Date.now() - 10*60*1000)) {
      return output.fresh();
   }
   store.set('staffList.isFetching', true);
   output.stale();
}

checkStaffList.outputs = {
   stale: {},
   fresh: {},
   fetching: {}
};

Fix

// Just call your outputs with an empty object
function checkStaffList (input, store, output) {
   const list = store.get('staffList');
   if (list.isFetching) return output.fetching({/* empty object */});
   if (list.lastUpdated > (Date.now() - 10*60*1000)) {
      return output.fresh({/* empty object */});
   }
   store.set('staffList.isFetching', true);
   output.stale({/* empty object */});
}

checkStaffList.outputs = {
   stale: {},
   fresh: {},
   fetching: {}
};
Clone this wiki locally
0