lodash#forEach JavaScript Examples

The following examples show how to use lodash#forEach. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.js    From hzero-front with Apache License 2.0 7 votes vote down vote up
/**
 * 合并 Descriptor 后的属性
 * @param {Object} dealProps2 - 组件属性处理后的属性
 * @param {Object} contextProps - context 属性
 */
function mergeProps(dealProps2, contextProps) {
  const dealProps3 = cloneDeep(dealProps2);
  forEach(contextProps, (_, contextPropKey) => {
    Object.defineProperty(
      dealProps3,
      contextPropKey,
      Object.getOwnPropertyDescriptor(contextProps, contextPropKey)
    );
  });
  return dealProps3;
}
Example #2
Source File: TaskBoard.js    From covidsos with MIT License 6 votes vote down vote up
componentDidMount() {
    makeApiCall(config.volunteerRequests, 'GET', {}, (data) => {

      const completedTasks = [];
      const pendingTasks = [];

      forEach(data, ({status}, index) => {
        if (status === "completed") {
          completedTasks.push(data[index]);
        } else {
          pendingTasks.push(data[index]);
        }
      });

      this.setState({
        pendingTasks: pendingTasks,
        completedTasks: completedTasks
      })

    }, false);
  }
Example #3
Source File: initThemes.js    From matx-react with MIT License 6 votes vote down vote up
function createMatxThemes() {
  let themes = {};

  forEach(themeColors, (value, key) => {
    themes[key] = createTheme(merge({}, themeOptions, value));
  });

  return themes;
}
Example #4
Source File: MessagesList.js    From CyberStateRP with MIT License 5 votes vote down vote up
MessagesList = props => {
    const { phone } = useContext(PhoneContext)
    const getMessages = () => {
        const { myNumber } = phone
        const msgs = phone.messages
        const senders = reduce(msgs, (result, value, key) => {
            if (!result[value.sender_num] && value.sender_num !== myNumber) {
                result[value.sender_num] = [value]
            } else if (value.sender_num !== myNumber) {
                result[value.sender_num].push(value)
            }
            if (!result[value.creator_num] && value.creator_num !== myNumber) {
                result[value.creator_num] = [value]
            } else if (value.creator_num !== myNumber) {
                result[value.creator_num].push(value)
            }
            return result
        }, {})
        const messagesToRender = []
        forEach(senders, (v, k) => {
            //console.log(`${JSON.stringify(v)} ${k}`)
            messagesToRender.push(
                <Message
                    key={k}
                    contactNumber={k}
                    messages={v}
                />
            )
        })
        return messagesToRender
    }
    return (
        <div className="app messages">
            <div className="container">
                <div className="control-bar">
                    <div className="control inactive" />
                    <div className="control new">
                        <div className="icon">
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 23 23">
                                <path d="M21.735.369l.896.888a1.317 1.283 0 0 1 0 1.783l-.716.713-2.688-2.671.717-.713a1.248 1.216 0 0 1 1.791 0zm-10.736 14.236v.011l-3.021.447a.101.099 0 0 1-.115-.085.154.15 0 0 1 0-.03l.455-3.009h.01l-.01-.011 10.384-10.33.896.888-9.959 9.913a3.323 3.238 0 0 0 .382.517 2.909 2.835 0 0 0 .507.365v.008l9.966-9.91.895.888-10.384 10.336zm4.197-10.759l-1.013 1.009h-13.17v17.138l17.222-.016v-13.09l1.013-1.008v15.121l-19.248-.016v-19.139z" />
                            </svg>
                        </div>
                    </div>
                </div>
                <div className="title-bar">
                    <div className="title">Messages</div>
                </div>
                <div className="workspace">
                    {getMessages()}
                </div>
            </div>
        </div>
    )
}
Example #5
Source File: MessagesList.js    From CyberState with GNU General Public License v3.0 5 votes vote down vote up
MessagesList = props => {
    const { phone } = useContext(PhoneContext)
    const getMessages = () => {
        const { myNumber } = phone
        const msgs = phone.messages
        const senders = reduce(msgs, (result, value, key) => {
            if (!result[value.sender_num] && value.sender_num !== myNumber) {
                result[value.sender_num] = [value]
            } else if (value.sender_num !== myNumber) {
                result[value.sender_num].push(value)
            }
            if (!result[value.creator_num] && value.creator_num !== myNumber) {
                result[value.creator_num] = [value]
            } else if (value.creator_num !== myNumber) {
                result[value.creator_num].push(value)
            }
            return result
        }, {})
        const messagesToRender = []
        forEach(senders, (v, k) => {
            //console.log(`${JSON.stringify(v)} ${k}`)
            messagesToRender.push(
                <Message
                    key={k}
                    contactNumber={k}
                    messages={v}
                />
            )
        })
        return messagesToRender
    }
    return (
        <div className="app messages">
            <div className="container">
                <div className="control-bar">
                    <div className="control inactive" />
                    <div className="control new">
                        <div className="icon">
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 23 23">
                                <path d="M21.735.369l.896.888a1.317 1.283 0 0 1 0 1.783l-.716.713-2.688-2.671.717-.713a1.248 1.216 0 0 1 1.791 0zm-10.736 14.236v.011l-3.021.447a.101.099 0 0 1-.115-.085.154.15 0 0 1 0-.03l.455-3.009h.01l-.01-.011 10.384-10.33.896.888-9.959 9.913a3.323 3.238 0 0 0 .382.517 2.909 2.835 0 0 0 .507.365v.008l9.966-9.91.895.888-10.384 10.336zm4.197-10.759l-1.013 1.009h-13.17v17.138l17.222-.016v-13.09l1.013-1.008v15.121l-19.248-.016v-19.139z" />
                            </svg>
                        </div>
                    </div>
                </div>
                <div className="title-bar">
                    <div className="title">Сообщения</div>
                </div>
                <div className="workspace">
                    {getMessages()}
                </div>
            </div>
        </div>
    )
}
Example #6
Source File: index.js    From hzero-front with Apache License 2.0 5 votes vote down vote up
export default function cacheComponent({ cacheKey, cachePreKey = getActiveTabKey() } = {}) {
  return (Component) =>
    class CacheComponent extends React.Component {
      loadCache(component, callback) {
        if (cacheKey) {
          const { form } = component.props;
          const cache = getCache(cacheKey);
          if (form && cache && cache.form) {
            if (isObject(cache.form)) {
              Object.keys(cache.form).forEach((item) => form.registerField(item));
            }
            form.setFieldsValue(cache.form);
          }

          if (cache && cache.state) {
            component.setState(cache.state, () => {
              if (callback) callback();
            });
          } else if (callback) {
            callback();
          }
        }
      }

      componentWillUnmount() {
        // if(CLEAR_MAP[cacheKey]){
        //   delete CLEAR_MAP[cacheKey];
        // }else{
        if (cacheKey && this.pageComponent) {
          const { form } = this.pageComponent.props;
          const cache = {};
          if (form) {
            const { getFieldsValue } = form;
            cache.form = getFieldsValue();
          }

          if (this.pageComponent.state) {
            cache.state = this.pageComponent.state;
          }
          // setCache(cacheKey,cache);
          emitter.emit('save', cacheKey, cache, cachePreKey);
        }
        // }
      }

      setComponent = (component) => {
        this.pageComponent = component;
      };

      fakeComponentDidMount(Comp) {
        if (Comp._isFakeComponentDidMount !== true) {
          const { componentDidMount } = Comp.prototype;
          const { loadCache } = this;
          Comp.prototype.componentDidMount = function newComponentDidMount() {
            emitter.emit('willCache', cachePreKey);
            loadCache(this, () => {
              if (typeof componentDidMount === 'function') {
                componentDidMount.call(this);
              }
            });
          };
          Comp._isFakeComponentDidMount = true;
        }
      }

      render() {
        this.fakeComponentDidMount(Component);
        return <Component ref={this.setComponent} {...this.props} />;
      }
    };
}