Project

General

Profile

Enhancement(機能追加・改善) #4183

JavaScript から route (app_url_for, url_for) を呼び出せる機能が欲しい

Added by Shinichi Urabe over 2 years ago. Updated about 2 years ago.

Status:
Pending Review(レビュー待ち)
Priority:
Normal(通常)
Target version:
Start date:
2017-04-04
Due date:
% Done:

50%


Description

概要

JS から app_url_for, url_for などのヘルパーの結果を問い合わせる機構の作成

仕様

opUrl.app_url_for

jsDoc
  /** 
   * method app_url_for().
   *
   * @param  {strina} application ex: api ...
   * @param  {string} internalUri 'module/action' or '@rule' of the action
   * @param {boolean} absolute  return absolute path?
   * @returns {Deferred} Return a Deferred's Promise object. opUrl.url_for(... snip ...).done(function(url) {... snip ...}).fail(function(xhr, textStatus, errorThrown) {... snip ...})
   */

code example.

// no problem url.
opUrl.app_url_for(
  'api',
  '@homepage',
  false
).done(function(url) { console.log(url); });

// -> /api.php/

// invalidUrl
opUrl.app_url_for(
  'api',
  '@invalidUrl',
  false
).done(
  function(url) { console.log(url); }
).fail(
  function(xhr, textStatus, errorThrown) { console.log(xhr, textStatus, errorThrown); }
);

// -> xhr object, status, error


opUrl.url_for

for pc_frontend.

jsDoc
  /** 
   * method url_for().
   *
   * @param {string} internalUri 'module/action' or '@rule' of the action
   * @param {boolean} absolute  return absolute path?
   * @returns {Deferred} Return a Deferred's Promise object. opUrl.url_for(... snip ...).done(function(url) {... snip ...}).fail(function(xhr, textStatus, errorThrown) {... snip ...})
   */

code example.

// no problem url.
opUrl.url_for(
  '@homepage',
  true,
).done(function(url) { console.log(url); });

// -> http://example.com/

// invalidUrl
opUrl.url_for(
  '@invalidUrl',
  true,
).done(
  function(url) { console.log(url); }
).fail(
  function(xhr, textStatus, errorThrown) { console.log(xhr, textStatus, errorThrown); }
);

// -> xhr object, status, error


History

#1 Updated by Shinichi Urabe about 2 years ago

  • Status changed from New(新規) to Accepted(着手)
  • Assignee set to Shinichi Urabe

#2 Updated by Shinichi Urabe about 2 years ago

  • Subject changed from JavaScript から route (app_url_for, url_for ) を呼び出せる機能が欲しい to JavaScript から route (app_url_for, url_for) を呼び出せる機能が欲しい
  • Description updated (diff)
  • Status changed from Accepted(着手) to Pending Review(レビュー待ち)
  • % Done changed from 0 to 50

#3 Updated by Shinichi Urabe about 2 years ago

  • Status changed from Pending Review(レビュー待ち) to Rejected(差し戻し)

「引数でcallback渡すよりはPromise的なオブジェクトを返した方が今どきな感じがありそう」 という意見をもらったので、折角なので、その方針で検討

#4 Updated by Shinichi Urabe about 2 years ago

  • Description updated (diff)
  • Status changed from Rejected(差し戻し) to Pending Review(レビュー待ち)

追加修正で callback を引数に追加させるのをやめ、 Deferred.Promise オブジェクトを返すようにした
PR: https://github.com/openpne/OpenPNE3/pull/471

Also available in: Atom PDF