beagle: eq doesn't work

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

Please provide a clear and concise description of what the bug is. Include screenshots if needed. Please test using the latest Beagle release to make sure your issue has not already been fixed: https://github.com/ZupIT/beagle/releases

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Launch the playground
  2. Run conditional-action.json with modification: replace gte function with eq function …
"onPress": [
        {
          "_beagleAction_": "beagle:condition",
          "condition": "@{eq(user.age, 18)}",
          "onTrue": [
            {

Expected Results

Setting the age to 18 will result buying a beer.

What actually happen: never able to buy a beer.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

Hi @TomerPacific. We really appreciate your help, but we need this feature asap. For this reason, @hernandazevedozup will pick this up from where you left it.

@TomerPacific This will depend on the language you’re using. If the language can sum Int and Double and give you a Double result, then you don’t need to do anything else, the language itself made these conversions under the hood for you.

In the case of Kotlin, you can ignore this statement (line 2).

@TomerPacific tyvm for your contribution. I’ll ask @hernandazevedozup to take a look and get back to you asap!

Hi @Tiagoperes , would you like help with this issue?

Added to the backlog:

1. Make the following operations agnostic to the type of the data: eq, gt, lt, gte, lte.

  • If one is a string and the other is an integer, parse the string to integer using the decimal base and then compare. If there’s a parse error, return false.
  • If one is a string and the other is double, parse the string to double using the decimal base and . as the decimal part separator. If there’s a parse error, return false.
  • If one is an integer and the other is a double, check if the decimal part of the double is 0, if it is, compare the integer part. Otherwise, return false.

2. Make the following operations agnostic to the type of the data: sum, subtract, multiply, divide.

  • The result type should be: a double if the operation is divide; a double if at least one of the arguments is a double or a string representing a double; an integer otherwise.
  • If the result type is double and an argument is an integer, the argument should be converted to double.
  • If the result type is double and an argument is a string, the argument should be parsed to double using the decimal system and .as the decimal separator.
  • If the result type is integer and an argument is a string, the argument should be parsed to integer using the decimal system.

3. Create operations to convert types:

  • int(String): parses the String into an integer (decimal). On parse error return NaN, if supported, or null otherwise.
  • int(Double): converts the Double into an Integer by truncating its decimal part.
  • double(String): parses the String into a double (decimal, . as the separator). On parse error return NaN, if supported, or null otherwise.
  • double(Int): converts the Integer into a Double.
  • string(Int): creates a string representation of the integer.
  • string(Double): creates a string representation of the double (. as the separator).

Platforms

1 and 2 should be implemented on Android and iOS. 3 should also be implemented on web platforms.

Hi @brianchu, hope you’re ok!

I figured you’re referring to this example: https://playground.usebeagle.io/#/demo/component-interaction/condional-action.json?platform=ios

I checked and there’s a bug with Beagle Android and Beagle iOS. The comparison operations should make automatic type coercions. It gives you false because the string “18” is not equal to the integer 18. It is a string because the value comes from a text field.

We’ll fix this to make every comparison function auto coerce Strings to Int or Doubles if they represent these types, but while this is not fixed, you can use a custom operation as a workaround.

You can either create a custom operation eq with type coercion or implement an operation that converts string to Int.

Example of the second: eq(int(user.age), 18).

Documentation for custom operations: https://docs.usebeagle.io/v2.0/api/operations/how-to-register-a-new-operation/