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


TypeScript common.Prop類代碼示例

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


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

示例1: ctrl

export function ctrl(initChapters: StudyChapterMeta[], send: SocketSend, setTab: () => void, chapterConfig, root: AnalyseCtrl): StudyChaptersCtrl {

  const list: Prop<StudyChapterMeta[]> = prop(initChapters);

  const newForm = chapterNewForm(send, list, setTab, root);
  const editForm = chapterEditForm(send, chapterConfig, root.redraw);

  const localPaths: LocalPaths = {};

  return {
    newForm,
    editForm,
    list,
    get(id) {
      return list().find(c => c.id === id);
    },
    size() {
      return list().length;
    },
    sort(ids) {
      send("sortChapters", ids);
    },
    firstChapterId() {
      return list()[0].id;
    },
    toggleNewForm() {
      if (newForm.vm.open || list().length < 64) newForm.toggle();
      else alert("You have reached the limit of 64 chapters per study. Please create a new study.");
    },
    localPaths
  };
}
開發者ID:ddugovic,項目名稱:lila,代碼行數:32,代碼來源:studyChapters.ts

示例2: ctrl

export function ctrl(send: SocketSend, members: Prop<StudyMemberMap>, setTab: () => void, redraw: () => void) {
  const open = prop(false);
  let followings = [];
  let spectators = [];
  function updateFollowings(f) {
    followings = f(followings);
    if (open()) redraw();
  };
  return {
    open,
    candidates() {
      const existing = members();
      return followings.concat(spectators).filter(function(elem, idx, arr) {
        return arr.indexOf(elem) >= idx && // remove duplicates
          !existing.hasOwnProperty(titleNameToId(elem)); // remove existing members
      }).sort();
    },
    members,
    setSpectators(usernames) {
      spectators = usernames;
    },
    setFollowings(usernames) {
      updateFollowings(_ => usernames)
    },
    delFollowing(username) {
      updateFollowings(function(prevs) {
        return prevs.filter(function(u) {
          return username !== u;
        });
      });
    },
    addFollowing(username) {
      updateFollowings(function(prevs) {
        return prevs.concat([username]);
      });
    },
    toggle() {
      open(!open());
      if (open()) send('following_onlines');
    },
    invite(titleName) {
      send("invite", titleNameToId(titleName));
      setTab();
    },
    redraw
  };
};
開發者ID:ornicar,項目名稱:lila,代碼行數:47,代碼來源:inviteForm.ts

示例3: requestAnalysisButton

function requestAnalysisButton(ctrl: AnalyseController, inProgress: Prop<boolean>, notify: (msg: string) => void) {
  if (inProgress()) return h('p', 'Server-side analysis in progress');
  if (ctrl.ongoing || ctrl.synthetic) return undefined;
  return h('button', {
    hook: bind('click', _ =>  {
      $.ajax({
        method: 'post',
        url: `/${ctrl.data.game.id}/request-analysis`,
        success: () => {
          inProgress(true);
          notify('Server-side analysis in progress')
        },
        error: () => notify('Cannot run server-side analysis'),
      });
    })
  }, 'Request a computer analysis');
}
開發者ID:ornicar,項目名稱:lila,代碼行數:17,代碼來源:nvui.ts

示例4: submitMultiPgn

 function submitMultiPgn(d) {
   if (d.pgn) {
     const lines = d.pgn.split('\n');
     const parts = lines.map(function(l, i) {
       // ensure 2 spaces after each game
       if (!l.trim() && i && lines[i - 1][0] !== '[') return '\n';
       return l;
     }).join('\n').split('\n\n\n').map(function(part) {
       // remove empty lines in each game
       return part.split('\n').filter(identity).join('\n');
     }).filter(identity); // remove empty games
     if (parts.length > 1) {
       if (parts.length > multiPgnMax && !confirm('Import the first ' + multiPgnMax + ' of the ' + parts.length + ' games?')) return;
       const step = function(ds) {
         if (ds.length) {
           send('addChapter', ds[0]);
           setTimeout(function() {
             step(ds.slice(1));
           }, 600);
         } else {}
       };
       const firstIt = vm.initial() ? 1 : (chapters().length + 1);
       step(parts.slice(0, multiPgnMax).map(function(pgn, i) {
         return {
           initial: !i && vm.initial(),
           mode: d.mode,
           name: 'Chapter ' + (firstIt + i),
           orientation: d.orientation,
           pgn,
           variant: d.variant,
           sticky: root.study!.vm.mode.sticky
         };
       }));
       return true;
     }
   }
 };
開發者ID:lexisvar,項目名稱:lila,代碼行數:37,代碼來源:chapterNewForm.ts

示例5: inProgress

 success: () => {
   inProgress(true);
   notify('Server-side analysis in progress')
 },
開發者ID:ornicar,項目名稱:lila,代碼行數:4,代碼來源:nvui.ts


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