ramda#set TypeScript Examples

The following examples show how to use ramda#set. 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: population.service.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
public async populateContent(contentFields: Record<string, unknown>, contentTypeFields: ContentTypeField[] | PageTypeField[]): Promise<Record<string, unknown>> {
		let fields = contentFields;
		const populationMap = this.createPopulateMap(contentFields, contentTypeFields);

		if (populationMap.length === 0) {
			return contentFields;
		}

		const contentItemUuids = populationMap
			.filter(x => x.type === 'content')
			.map(x => x.contentUuid);
		const pageItemUuids = populationMap
			.filter(x => x.type === 'page')
			.map(x => x.contentUuid);

		const [contentItems, pageItems] = await Promise.all([
			contentItemUuids.length ? this.contentRepository.createQueryBuilder('Content')
				.where("Content.uuid IN (:...uuids)", { uuids: [...new Set(contentItemUuids)]})
				.getMany() : Promise.resolve([]),
			pageItemUuids.length ? this.pageRepository.createQueryBuilder('Page')
				.where("Page.pageTypeUuid IN (:...uuids)", { uuids: [...new Set(pageItemUuids)]})
				.getMany() : Promise.resolve([])
		])
			
		populationMap.forEach((population) => {
			const contentItem = population.type === 'content' ?
				contentItems.find(x => x.uuid === population.contentUuid) :
				pageItems.find(x => x.pageTypeUuid === population.contentUuid);

			fields = set(lensPath([...population.fieldPath]), contentItem)(fields)
		})
		
		return fields;
	}
Example #2
Source File: reducer.ts    From react-js-tutorial with MIT License 5 votes vote down vote up
gameSlice = createSlice({
  name: "game",
  initialState,
  reducers: {
    rebuild: (state) => ({
      ...state,
      gameStatus: GameStatus.NewGame,
      gameField: createEmptyGameField(...state.fieldSize),
    }),
    createGameWithParams: (state, { payload }: RebuildActionType) => {
      const fieldSize = payload.fieldSize ?? state.fieldSize;
      return {
        ...state,
        gameStatus: GameStatus.NewGame,
        fieldSize,
        playerMarks: payload.playerMarks ?? state.playerMarks,
        nextTurn: payload.nextTurn ?? state.nextTurn,
        gameField: createEmptyGameField(...fieldSize),
      };
    },
    click: (state, { payload }: ClickActionType) => {
      const { x, y } = payload;
      const { nextTurn, gameField, moves, gameStatus } = state;
      if (gameStatus !== GameStatus.GameOver) {
        return {
          ...state,
          gameField: set(lensPath([y, x]), nextTurn, gameField),
          nextTurn:
            nextTurn === firstPlayerMark ? secondPlayerMark : firstPlayerMark,
          moves: moves + 1,
        };
      }
      return state;
    },
    changeStatus: (state, { payload }: ChangeStatusActionType) => ({
      ...state,
      gameStatus: payload,
    }),
    setWinner: (state, { payload }: SetWinnerActionType) => ({
      ...state,
      winner: payload,
    }),
  },
})
Example #3
Source File: dashboard.page.ts    From radiopanel with GNU General Public License v3.0 5 votes vote down vote up
public handleConfiguration(index: number, data: any): void {
		this.configurations = set(lensPath([index, 'data']), data)(this.configurations);
		this.pushNewDashboard();
	}