Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper for closures and non-static methods #163

Open
2bad2furious opened this issue Aug 5, 2017 · 7 comments
Open

Helper for closures and non-static methods #163

2bad2furious opened this issue Aug 5, 2017 · 7 comments

Comments

@2bad2furious
Copy link
Contributor

2bad2furious commented Aug 5, 2017

  • bug report? no
  • feature request? yes
  • version: 2.4.5

Description

I think it would be great to have helpers for closures and non-static methods. It can make JS validation easier and could lead to better code-writing. Correct me if I'm wrong, but for a good JS validation you have to use static methods or named functions that honestly don't belong there.

Naming those methods and closures could look like:

  • Non-static methods' names could replace named functions
    (Class->methodname would result in {"op":"methodname",...})
  • Non-static methods' names could look similar to current static methods' names
    (Class->methodname would result in {"op":"Class[some separator]methodname"})
  • Closures' names could be generated by the name attribute as seen in my example below
  • Users could name methods and closures themselves

exportRules() EXAMPLE

public static function exportRules(Rules $rules) {
$payload = [];
foreach ($rules as $rule_key => $rule) {
if (!is_string($op = $rule->validator)) {
$callback_name = Nette\Utils\Callback::toString($op);
if ($callback_name === "{closure}") {
$op = $rule->control->getName() . "_rule" . $rule_key;
} else if (Nette\Utils\Callback::isStatic($op)) {
$op = $callback_name;
} else {
//TODO replace for better separator instead of :: (requires js changes as well :/
$op = $callback_name;
}
/*
* Original code that started on line 100 after 'if(!is_string...'
*
* if (!Nette\Utils\Callback::isStatic($op)) {
continue;
}
$op = Nette\Utils\Callback::toString($op);*/
}
//method continues as it should

2bad2furious pushed a commit to 2bad2furious/nette-sams-game-site that referenced this issue Aug 5, 2017
2bad2furious pushed a commit to 2bad2furious/nette-sams-game-site that referenced this issue Aug 5, 2017
@dg
Copy link
Member

dg commented Aug 5, 2017

Please use only english on GitHub.

@2bad2furious
Copy link
Contributor Author

Rewriten in English.

@dg
Copy link
Member

dg commented Aug 5, 2017

Thanks

@2bad2furious 2bad2furious changed the title Helper pro closures a nestatické metody. Helper for closures and non-static methods Aug 5, 2017
@dg
Copy link
Member

dg commented Aug 20, 2017

Non-static methods' names could look similar to current static methods' names
(Class->methodname would result in {"op":"Class[some separator]methodname"})

👍

Closures' names could be generated by the name attribute as seen in my example below

👎 it is too tricky

Users could name methods and closures themselves

That would be fine, but there is no way to do it.

@2bad2furious
Copy link
Contributor Author

2bad2furious commented Aug 20, 2017

You could achieve that by doing something like $form->....->addRule(callable,"name");
I don't think anything would change for other types of functions.

@dg
Copy link
Member

dg commented Aug 20, 2017

How is this related with onSuccess?

@2bad2furious
Copy link
Contributor Author

Brainlag, sry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants