lodash-es#cloneDeep TypeScript Examples

The following examples show how to use lodash-es#cloneDeep. 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: DiamondNodeModel.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
getNodeStyle() {
    const style = super.getNodeStyle();
    const {
      graphModel: {
        theme: {
          diamond,
        },
      },
    } = this;
    return {
      ...style,
      ...cloneDeep(diamond),
    };
  }
Example #2
Source File: farms.ts    From raydium-ui with GNU General Public License v3.0 6 votes vote down vote up
export function getFarmByPoolId(poolId: string): FarmInfo | undefined {
  const farm = FARMS.find((farm) => farm.poolId === poolId)

  if (farm) {
    return cloneDeep(farm)
  }

  return farm
}
Example #3
Source File: farm.ts    From raydium-ui with GNU General Public License v3.0 6 votes vote down vote up
mutations = mutationTree(state, {
  setInitialized(state) {
    state.initialized = true
  },

  setLoading(state, loading: boolean) {
    if (loading) {
      state.countdown = AUTO_REFRESH_TIME
    }

    state.loading = loading

    if (!loading) {
      state.countdown = 0
    }
  },

  setInfos(state, infos: object) {
    state.infos = cloneDeep(infos)
  },

  setStakeAccounts(state, stakeAccounts) {
    state.stakeAccounts = cloneDeep(stakeAccounts)
  },

  setAuxiliaryStakeAccounts(state, auxiliaryStakeAccounts) {
    state.auxiliaryStakeAccounts = cloneDeep(auxiliaryStakeAccounts)
  },

  setCountdown(state, countdown: number) {
    state.countdown = countdown
  },

  setLastSubBlock(state, lastSubBlock: number) {
    state.lastSubBlock = lastSubBlock
  }
})
Example #4
Source File: ido.ts    From raydium-ui with GNU General Public License v3.0 6 votes vote down vote up
export function getIdoPoolById(idoId: string) {
  const pool = IDO_POOLS.find((pool) => pool.idoId === idoId)

  if (pool) {
    return cloneDeep(pool)
  }

  return pool
}
Example #5
Source File: use-preview.ts    From bext with MIT License 6 votes vote down vote up
usePreview = (disableDraft: boolean = false /* 不可变 */) => {
  const [{ previewId, previewMeta }] = useUrlState({
    previewMeta: undefined,
    previewId: undefined,
  });

  const { draft } = disableDraft ? { draft: null } : useDraft();

  const getPreviewMeta = useCallback<() => Promise<Meta>>(async () => {
    switch (previewMeta) {
      case 'draft':
        return defaults(cloneDeep(draft), {
          id: previewId,
          version: '请填写版本',
          name: '请填写脚本名称',
          tags: [],
          synopsis: '请填写脚本简介',
          detail: '请填写脚本详情',
          type: 'javascript',
          source: '',
        });
      default:
        const response = await fetch(previewMeta);
        return Object.assign({}, await response.json(), {
          id: String(previewId),
        });
    }
  }, [previewMeta, previewId, draft]);

  return {
    previewId,
    previewMeta,
    getPreviewMeta,
  };
}
Example #6
Source File: tokens.ts    From raydium-ui with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get token use symbol

 * @param {string} symbol

 * @returns {TokenInfo | null} tokenInfo
 */
export function getTokenBySymbol(symbol: string): TokenInfo | null {
  if (symbol === 'SOL') {
    return cloneDeep(NATIVE_SOL)
  }

  let token = cloneDeep(TOKENS[symbol])

  if (!token) {
    token = null
  }

  return token
}
Example #7
Source File: ido.ts    From raydium-ui with GNU General Public License v3.0 6 votes vote down vote up
mutations = mutationTree(state, {
  setInitialized(state) {
    state.initialized = true
  },

  setLoading(state, loading: boolean) {
    if (loading) {
      state.countdown = AUTO_REFRESH_TIME
    }

    state.loading = loading

    if (!loading) {
      state.countdown = 0
    }
  },

  setPools(state, pools: Array<IdoPool>) {
    state.pools = cloneDeep(pools)
  },

  setCountdown(state, countdown: number) {
    state.countdown = countdown
  },

  setLastSubBlock(state, lastSubBlock: number) {
    state.lastSubBlock = lastSubBlock
  }
})
Example #8
Source File: tokens.ts    From raydium-ui with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get token use mint addresses

 * @param {string} mintAddress

 * @returns {TokenInfo | null} tokenInfo
 */
export function getTokenByMintAddress(mintAddress: string): TokenInfo | null {
  if (mintAddress === NATIVE_SOL.mintAddress) {
    return cloneDeep(NATIVE_SOL)
  }
  const token = Object.values(TOKENS).find((item) => item.mintAddress === mintAddress)
  return token ? cloneDeep(token) : null
}
Example #9
Source File: History.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
// 1) undo方法触发
  // 2) graphModel重新渲染nodes和edges
  // 3) graphModel发生变化,触发watch
  // 4) watch触发add
  undo() {
    if (!this.undoAble()) return;
    const preData = this.undos.pop();
    this.redos.push(preData);
    const curData = this.undos.pop();
    this.curData = cloneDeep(curData);
    return curData;
  }
Example #10
Source File: theme.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
updateTheme = (style: Theme) => {
  let defaultStyle = cloneDeep(defaultTheme);
  if (style) {
    /**
     * 为了不让默认样式被覆盖,改用merge
     * 例如:锚点主题hover
     * 用户传入
     * lf.setTheme({
     *   anchor: {
     *     hover: {
     *       fill: 'red'
     *     }
     *   }
     * })
     */
    defaultStyle = merge(defaultStyle, style);
    // Object.keys(style).forEach((key) => {
    //   defaultStyle[key] = { ...defaultStyle[key], ...style[key] };
    // });
  }
  return defaultStyle;
}
Example #11
Source File: animation.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
updateAnimation = (
  config: boolean | Partial<AnimationConfig>,
): AnimationConfig => {
  if (!config || typeof config === 'boolean') {
    // 不转类型
    return config === true
      ? cloneDeep(defaultAnimationOpenConfig)
      : cloneDeep(defaultAnimationCloseConfig);
  }

  // 传入的是对象AnimationConfig
  return merge(cloneDeep(defaultAnimationCloseConfig), config);
}
Example #12
Source File: farms.ts    From raydium-ui with GNU General Public License v3.0 6 votes vote down vote up
export function getFarmByRewardMintAddress(lpMintAddress: string): FarmInfo | undefined {
  const farm = FARMS.find((farm) => farm.reward.mintAddress === lpMintAddress)

  if (farm) {
    return cloneDeep(farm)
  }

  return farm
}
Example #13
Source File: liquidity.ts    From raydium-ui with GNU General Public License v3.0 6 votes vote down vote up
mutations = mutationTree(state, {
  setInitialized(state) {
    state.initialized = true
  },

  setLoading(state, loading: boolean) {
    if (loading) {
      state.countdown = AUTO_REFRESH_TIME
    }

    state.loading = loading

    if (!loading) {
      state.countdown = 0
    }
  },

  setInfos(state, infos: object) {
    state.infos = cloneDeep(infos)
  },

  setCountdown(state, countdown: number) {
    state.countdown = countdown
  },

  setLastSubBlock(state, lastSubBlock: number) {
    state.lastSubBlock = lastSubBlock
  }
})
Example #14
Source File: PolygonNodeModel.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
getNodeStyle() {
    const style = super.getNodeStyle();
    const {
      graphModel: {
        theme: {
          polygon,
        },
      },
    } = this;
    return {
      ...style,
      ...cloneDeep(polygon),
    };
  }
Example #15
Source File: EllipseNodeModel.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
getNodeStyle() {
    const style = super.getNodeStyle();
    const {
      graphModel: {
        theme: {
          ellipse,
        },
      },
    } = this;
    return {
      ...style,
      ...cloneDeep(ellipse),
    };
  }
Example #16
Source File: CircleNodeModel.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
getNodeStyle() {
    const style = super.getNodeStyle();
    const {
      graphModel: {
        theme: {
          circle,
        },
      },
    } = this;
    return {
      ...style,
      ...cloneDeep(circle),
    };
  }
Example #17
Source File: BaseNodeModel.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
/**
   * @overridable 支持重写
   * 获取outline样式,重写可以定义此类型节点outline样式, 默认使用主题样式
   * @returns 自定义outline样式
   */
  getOutlineStyle(): OutlineTheme {
    const { outline } = this.graphModel.theme;
    return cloneDeep(outline);
  }
Example #18
Source File: BaseNodeModel.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
/**
   * @overridable 支持重写
   * 获取当前节点锚点拖出连线样式
   * @returns 自定义锚点拖出样式
   */
  getAnchorLineStyle() {
    const { anchorLine } = this.graphModel.theme;
    return cloneDeep(anchorLine);
  }
Example #19
Source File: BaseNodeModel.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
/**
   * @overridable 支持重写
   * 获取当前节点锚点样式
   * @returns 自定义样式
   */
  getAnchorStyle(anchorInfo): Record<string, any> {
    const { anchor } = this.graphModel.theme;
    // 防止被重写覆盖主题。
    return cloneDeep(anchor);
  }
Example #20
Source File: BaseNodeModel.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
/**
   * @overridable 支持重写
   * 获取当前节点文本样式
   */
  getTextStyle() {
    // 透传 nodeText
    const { nodeText } = this.graphModel.theme;
    return cloneDeep(nodeText);
  }
Example #21
Source File: farms.ts    From raydium-ui with GNU General Public License v3.0 6 votes vote down vote up
export function getFarmByLpMintAddress(lpMintAddress: string): FarmInfo | undefined {
  const farm = FARMS.find((farm) => farm.lp.mintAddress === lpMintAddress)

  if (farm) {
    return cloneDeep(farm)
  }

  return farm
}
Example #22
Source File: price.ts    From raydium-ui with GNU General Public License v3.0 6 votes vote down vote up
mutations = mutationTree(state, {
  setInitialized(state) {
    state.initialized = true
  },

  setLoading(state, loading: boolean) {
    if (loading) {
      state.countdown = AUTO_REFRESH_TIME
    }

    state.loading = loading

    if (!loading) {
      state.countdown = 0
    }
  },

  setPrices(state, prices: PricesData) {
    state.prices = cloneDeep(prices)
  },

  setCountdown(state, countdown: number) {
    state.countdown = countdown
  }
})
Example #23
Source File: BaseEdgeModel.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
/**
   * @overridable 支持重写
   * 获取outline样式,重写可以定义此类型边outline样式, 默认使用主题样式
   * @returns 自定义outline样式
   */
  getOutlineStyle(): OutlineTheme {
    const { graphModel } = this;
    const { outline } = graphModel.theme;
    return cloneDeep(outline);
  }
Example #24
Source File: BaseEdgeModel.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
/**
   * @overridable 支持重写
   * 获取当前边的动画样式
   * @returns 自定义边动画样式
   */
  getEdgeAnimationStyle() {
    const { edgeAnimation } = this.graphModel.theme;
    return cloneDeep(edgeAnimation);
  }
Example #25
Source File: BaseEdgeModel.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
/**
   * @overridable 支持重写
   * 获取当前边的动画样式
   * @returns 自定义边动画样式
   */
  getAnimation() {
    const { animationData } = this;
    return cloneDeep(animationData);
  }
Example #26
Source File: BaseEdgeModel.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
/**
   * @overridable 支持重写
   * 获取当前节点文本样式
   */
  getTextStyle() {
    // 透传 edgeText
    const { edgeText } = this.graphModel.theme;
    return cloneDeep(edgeText);
  }
Example #27
Source File: BaseEdgeModel.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
/**
   * @overridable 支持重写
   * 获取当前节点样式
   * @returns 自定义边样式
   */
  getEdgeStyle() {
    const { baseEdge } = this.graphModel.theme;
    return cloneDeep(baseEdge);
  }
Example #28
Source File: RectNodeModel.ts    From LogicFlow with Apache License 2.0 5 votes vote down vote up
getNodeStyle() {
    const style = super.getNodeStyle();
    const { rect } = this.graphModel.theme;
    return {
      ...style,
      ...cloneDeep(rect),
    };
  }
Example #29
Source File: swap.ts    From raydium-ui with GNU General Public License v3.0 5 votes vote down vote up
mutations = mutationTree(state, {
  setMarkets(state, markets: any) {
    state.markets = cloneDeep(markets)
  }
})