function load(id, secret) {
  return (dispatch, getState, { db }) => {
    if (!id) {
      dispatch(loadDefault());

      return Promise.resolve();
    }

    return db
      .getItem(id)
      .then((document) => {
        if (null === document) {
          return Promise.reject(Errors.NOT_FOUND);
        }

        return Promise.resolve(new Document(Immutable.fromJS(document)));
      })
      .catch(() => request
        .get(`/documents/${id}`)
        .set('Accept', 'application/json')
        .set('Content-Type', 'application/json')
        .then((res) => {
          dispatch(isOnline());

          return Promise.resolve(new Document({
            uuid: res.body.uuid,
            content: res.body.content,
            last_modified: res.body.last_modified,
            template: res.body.template || '', // avoid BC break
            readonly: res.body.readonly || false, // avoid BC break
          }));
        })
        .catch((err) => {
          if (err.response && 404 === err.response.statusCode) {
            return Promise.reject(Errors.NOT_FOUND);
          }

          dispatch(isOffline());

          return Promise.reject(Errors.SERVER_UNREACHABLE);
        }),
      )
      .then((document) => {
        const decryptedContent = decrypt(document.get('content'), secret);

        if (null === decryptedContent) {
          return Promise.reject(Errors.DECRYPTION_FAILED);
        }

        dispatch(loadSuccess(document.set('content', decryptedContent), secret));

        return Promise.resolve();
      })
      .catch((err) => {
        switch (err) {
          case Errors.NOT_FOUND:
            dispatch(notFound());
            break;

          case Errors.SERVER_UNREACHABLE:
            dispatch(serverUnreachable());
            break;

          case Errors.DECRYPTION_FAILED:
            dispatch(decryptionFailed());
            break;

          default: // well...
        }
      });
  };
}
An action creator that loads a document based on its id, and a secret key to
decrypt it. It looks into the local database first, and calls the API if the
local database does not return anything.