• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript normalizr.normalize函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中normalizr.normalize函数的典型用法代码示例。如果您正苦于以下问题:TypeScript normalize函数的具体用法?TypeScript normalize怎么用?TypeScript normalize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了normalize函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: todo

export function todo(
  state = Record<TodoStateProp>({
    todoBoxId: null,
    todoIds: List(),
    todoEntities: Map(),
    todoBoxEntities: Map(),
    todoBoxIds: List()
  })(),
  action: any
) {
  switch (action.type) {
    case Actions.ADD_TODO.SUCCESS:
      const addedTodo = action.payload;
      return state
        .update('todoEntities', (todoEntities: any) =>
          todoEntities.set(String(addedTodo.id), fromJS(addedTodo))
        )
        .update('todoIds', (todoIds: any) => todoIds.push(String(addedTodo.id)));

    case Actions.GET_TODOLIST.REQUEST:
      return state.update('todoIds', () => List());

    case Actions.GET_TODOLIST.SUCCESS:
      const normalizedTodos = normalize(action.payload, TDS);
      return state
        .update('todoIds', () => List(normalizedTodos.result))
        .update('todoEntities', () => fromJS(normalizedTodos.entities.Todo || {}));

    case Actions.UPDATE_TODO.SUCCESS:
      return state.updateIn(['todoEntities', String(action.payload.id)], () =>
        fromJS(action.payload)
      );

    case Actions.DESTORY_TODO.SUCCESS:
      const toDeletedIndex = state.get('todoIds')!.indexOf(action.meta.id);
      return state.update('todoIds', (ids: any) => ids.delete(toDeletedIndex));

    case Actions.ADD_TODOBOX.SUCCESS:
      const normalizedAddedTodoBox = normalize(action.payload, TDBox);
      return state
        .update('todoBoxEntities', (todoBoxEntities: any) =>
          todoBoxEntities.merge(normalizedAddedTodoBox.entities.TodoBox)
        )
        .update('todoBoxIds', (todoBoxIds: any) => todoBoxIds.push(normalizedAddedTodoBox.result));

    case Actions.GET_TODOBOXS.SUCCESS:
      const normalizeTodoBox = normalize(action.payload, TDBoxs);
      return state
        .update('todoBoxIds', () => List(normalizeTodoBox.result))
        .update('todoBoxEntities', () => fromJS(normalizeTodoBox.entities.TodoBox || {}));

    default:
      return state;
  }
}
开发者ID:A-Horse,项目名称:bblist,代码行数:55,代码来源:todo.reducer.ts


示例2: return

 return (dispatch, store) => {
   let normalized = normalize(data.entries, arrayOf(schema));
   // This is for testing only. If no results are returned, Normalizr will 
   // return result: [ undefined ] and entities[entity] = {undefined:{}}.
   if (normalized.result[0] === undefined) {
     normalized.result.length = 0;
     normalized.entities[toCamelCase(name)] = {};
   }
   // Dispatch event for the main data that was gathered on this request.
   // This includes metadata about the collection.
   dispatch(action(FIND, name.toUpperCase(), {
     result: normalized.result,
     items: normalized.entities[toCamelCase(name)],
     meta: {
       count: data.total_entries,
       page: data.page,
       links: data._links
     }
   }));
   
   // Iterate over other objects that were returned (normalized) and 
   // dispatch add actions for them to get them into the store.
   for (let x in normalized.entities) {
     // Exclude main entity
     if (toLoudSnakeCase(x) !== toLoudSnakeCase(name)) {
       // Iterate over each object passed back and dispatch ADD action
       for (let y in normalized.entities[x]) {
         dispatch(action(ADD, toLoudSnakeCase(x), normalized.entities[x][y]));
       }
     }
   }
 }
开发者ID:jacobmumm,项目名称:restore,代码行数:32,代码来源:splitSchema.ts


示例3: function

 let processJob = function (job: JobModel) {
   let uniqueName = getJobIndexName(job.unique_name);
   if (!_.includes(newState.uniqueNames, uniqueName)) {
     newState.uniqueNames.push(uniqueName);
   }
   let normalizedJobs = normalize(job, JobSchema).entities.jobs;
   newState.byUniqueNames[uniqueName] = {
     ...newState.byUniqueNames[uniqueName], ...normalizedJobs[job.unique_name]
   };
   return newState;
 };
开发者ID:ttsvetanov,项目名称:polyaxon,代码行数:11,代码来源:jobs.ts


示例4: normalize

  protected normalize(response, schema) {

    let camelizedJson = camelizeKeys(response);

    let normalizedResponse = normalize(camelizedJson, schema);

    return {
      result: fromJS(normalizedResponse.result),
      entities: fromJS(normalizedResponse.entities)
    };
  }
开发者ID:dghijben,项目名称:dashboard,代码行数:11,代码来源:Api.ts


示例5: switch

export const users: Reducer<any> = (state = initialState, action: Action) => {
  switch (action.type) {
    case LOADING_USERS:
    case LOADING_USER:
      return state.set('loading', true);
    case LOADED_USERS:
      const normalizedUsers: IUsers = normalize(action.payload, arrayOf(userSchema));

      return state.withMutations(map => {
        map.set('loading', false);
        map.set('result', List(normalizedUsers.result));
        normalizedUsers.result.forEach((userId: number) => {
          map.setIn(
            ['entities', 'users', userId],
            new UserRecord(normalizedUsers.entities.users[userId])
          );
        });
      });
    case LOADED_USER:
      return state.withMutations(map => {
        map.set('loading', false);
        if (map.get('result').indexOf(action.payload.id) === -1) {
          map.update('result', list => list.push(action.payload.id));
        }
        map.setIn(
          ['entities', 'users', action.payload.id],
          new UserRecord(action.payload)
        );
      });
    case DELETING_USER:
      return state.setIn(['entities', 'users', action.payload.id, 'deleting'], true);
    case DELETED_USER:
      return state.withMutations(map => map
        .deleteIn(['entities', 'users', action.payload])
        .deleteIn(['result', map.get('result').indexOf(action.payload)])
      );
    case ADDING_USER:
      return state.set('adding', true);
    case ADDED_USER:
      return state.withMutations(map => map
        .setIn(['entities', 'users', action.payload.id], new UserRecord(action.payload))
        .update('result', list => list.push(action.payload.id))
        .set('adding', false)
      );
    case PATCHED_USER:
      return state
        .setIn(['entities', 'users', action.payload.id], new UserRecord(action.payload));

    default:
      return state;
  }
};
开发者ID:Anhmike,项目名称:angular2-store-example,代码行数:52,代码来源:users.ts


示例6: switch

export const posts: Reducer<any> = (state = initialState, action: Action) => {
  switch (action.type) {
    case LOADING_POSTS:
    case LOADING_POST:
      return state.set('loading', true)
    case LOADED_POSTS:
      const normalizedPosts: IPosts = normalize(action.payload, arrayOf(postSchema))
      return state.withMutations(map => {
        map.set('loading', false)
        map.set('result', List(normalizedPosts.result))
        normalizedPosts.result.forEach((postId: number) => {
          normalizedPosts.entities.posts[postId].user = normalizedPosts.entities.users[normalizedPosts.entities.posts[postId].user]
          map.setIn(
            ['entities', 'posts', postId],
            new PostRecord(normalizedPosts.entities.posts[postId])
          )
        })
      })
    case LOADED_POST:
      return state.withMutations(map => {
        map.set('loading', false)
        if (map.get('result').indexOf(action.payload.id) === -1) {
          map.update('result', list => list.push(action.payload.id))
        }
        map.setIn(
          ['entities', 'posts', action.payload.id],
          new PostRecord(action.payload)
        )
      })
    case DELETING_POST:
      return state.setIn(['entities', 'posts', action.payload.id, 'deleting'], true)
    case DELETED_POST:
      return state.withMutations(map => map
        .deleteIn(['entities', 'posts', action.payload])
        .deleteIn(['result', map.get('result').indexOf(action.payload)])
      )
    case ADDING_POST:
      return state.set('adding', true)
    case ADDED_POST:
      return state.withMutations(map => map
        .setIn(['entities', 'posts', action.payload.id], new PostRecord(action.payload))
        .update('result', list => list.push(action.payload.id))
        .set('adding', false)
      )
    case PATCHED_POST:
      return state
        .setIn(['entities', 'posts', action.payload.id], new PostRecord(action.payload))

    default:
      return state
  }
}
开发者ID:AmbientIT,项目名称:ng2Experiments,代码行数:52,代码来源:post.reducer.ts


示例7: function

 let processUser = function (user: UserModel) {
   if (!_.includes(newState.userNames, user.username)) {
     newState.userNames.push(user.username);
   }
   let normalizedUsers = normalize(user, UserSchema).entities.users;
   newState.byUserNames[user.username] = {
     ...newState.byUserNames[user.username], ...normalizedUsers[user.username]
   };
   if (newState.byUserNames[user.username].projects == null) {
     newState.byUserNames[user.username].projects = [];
   }
   return newState;
 };
开发者ID:ttsvetanov,项目名称:polyaxon,代码行数:13,代码来源:user.ts


示例8: function

 let processExperiment = function (experiment: ExperimentModel) {
   let uniqueName = getExperimentIndexName(experiment.unique_name);
   if (!_.includes(newState.uniqueNames, uniqueName)) {
     newState.uniqueNames.push(uniqueName);
   }
   let normalizedExperiments = normalize(experiment, ExperimentSchema).entities.experiments;
   newState.byUniqueNames[uniqueName] = {
     ...newState.byUniqueNames[uniqueName], ...normalizedExperiments[experiment.unique_name]
   };
   if (newState.byUniqueNames[uniqueName].jobs == null) {
     newState.byUniqueNames[uniqueName].jobs = [];
   }
   return newState;
 };
开发者ID:ttsvetanov,项目名称:polyaxon,代码行数:14,代码来源:experiments.ts


示例9: function

 let processGroup = function(group: GroupModel) {
   let uniqueName = group.unique_name;
   if (!_.includes(newState.uniqueNames, uniqueName)) {
     newState.uniqueNames.push(uniqueName);
   }
   let normalizedGroups = normalize(group, GroupSchema).entities.groups;
   newState.byUniqueNames[uniqueName] = {
     ...newState.byUniqueNames[uniqueName], ...normalizedGroups[uniqueName]
   };
   if (newState.byUniqueNames[uniqueName].experiments == null) {
     newState.byUniqueNames[uniqueName].experiments = [];
   }
   return newState;
 };
开发者ID:ttsvetanov,项目名称:polyaxon,代码行数:14,代码来源:groups.ts


示例10: function

 let processProject = function(project: ProjectModel) {
   let uniqueName = project.unique_name;
   if (!_.includes(newState.uniqueNames, uniqueName)) {
     newState.uniqueNames.push(uniqueName);
   }
   let normalizedProjects = normalize(project, ProjectSchema).entities.projects;
   newState.byUniqueNames[uniqueName] = {
     ...newState.byUniqueNames[uniqueName], ...normalizedProjects[uniqueName]
   };
   if (newState.byUniqueNames[uniqueName].experiments == null) {
     newState.byUniqueNames[uniqueName].experiments = [];
   }
   if (newState.byUniqueNames[uniqueName].groups == null) {
     newState.byUniqueNames[uniqueName].groups = [];
   }
   return newState;
 };
开发者ID:ttsvetanov,项目名称:polyaxon,代码行数:17,代码来源:projects.ts



注:本文中的normalizr.normalize函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript normalizr.Schema类代码示例发布时间:2022-05-25
下一篇:
TypeScript normalizr.arrayOf函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap