當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript normalizr.arrayOf函數代碼示例

本文整理匯總了TypeScript中normalizr.arrayOf函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript arrayOf函數的具體用法?TypeScript arrayOf怎麽用?TypeScript arrayOf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了arrayOf函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: normalize

 (res) => normalize(res, arrayOf(peopleSchema))
開發者ID:Lukinos,項目名稱:ngrx-example,代碼行數:1,代碼來源:people.sagas.ts

示例5: arrayOf

 .map((res) => this.normalize(res, arrayOf(taskSchema)));
開發者ID:dghijben,項目名稱:dashboard,代碼行數:1,代碼來源:TaskApi.ts

示例6: Schema

import {Schema, arrayOf} from 'normalizr';
import phone from './phone';


const contact = new Schema('contacts',{
    idAttribute: '_id'
});

contact.define({phones: arrayOf(phone)});

export default contact;
開發者ID:DaveMBush,項目名稱:MEA2N_CRUD_Reference_App,代碼行數:11,代碼來源:contact.ts

示例7: Schema

import { normalize, Schema, arrayOf, valuesOf } from "normalizr";
export var article = new Schema("articles");
export var comment = new Schema("comments");
export var user = new Schema("users");
article.define({
	get_comments : arrayOf(comment),
	get_author : user,
});

comment.define({
	get_author : user,
	get_article : article,
});

user.define({
	get_articles : arrayOf(article),
	get_comments : arrayOf(comment),
});
開發者ID:joewood,項目名稱:refluxion,代碼行數:18,代碼來源:test-model.normalizr.ts

示例8: require

const { Schema, arrayOf } = require('normalizr');

const userSchema = new Schema('users', {
  idAttribute: user => user.id
});

export const Schemas = {
  USER: userSchema,
  ALL_USERS: {
    users: arrayOf(userSchema)
  }
};
開發者ID:levinmr,項目名稱:angular2-webpack-redux,代碼行數:12,代碼來源:schemas.ts

示例9: arrayOf

 .map((res) => this.normalize(res, arrayOf(storySchema)));
開發者ID:dghijben,項目名稱:dashboard,代碼行數:1,代碼來源:StoryApi.ts

示例10: arrayOf

 .map((res) => this.normalize(res, arrayOf(projectSchema)));
開發者ID:dghijben,項目名稱:dashboard,代碼行數:1,代碼來源:ProjectApi.ts


注:本文中的normalizr.arrayOf函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。