question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

liquidMethodMissing doesn't support object promises

See original GitHub issue

Hi,

In attempt to implement a drop, i am trying to return an object from liquidMethodMissing method in order to lazily load objects.

For example:

class ProductsDrop extends Drop{
  constructor(api) {
      super()
  }
  async liquidMethodMissing(productHandle) {
      const product = this.api.getProductByHandle(productHandle)
      if (product) return product else return null
  }
}

and to call it as, for example: {{products[‘product handle’].name]}}

However, it seems that liquidMethodMissing supports only string type Promises.

  public liquidMethodMissing (key: string): Promise<string | undefined> | string | undefined {
    return undefined
  }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
almousa1990commented, Nov 28, 2020

I was able to resolve the issue by adding a simple condition to the readProperty function, i am not sure if it breaks something else!

export function readProperty (obj: Scope, key: string) {
  if (isNil(obj)) return obj
  obj = toLiquid(obj)
  if (obj instanceof Drop) {
    if (isFunction(obj[key])) return obj[key]()
    if (obj.hasOwnProperty(key)) return obj[key]
    return obj.liquidMethodMissing(key)
  }
// HERE
  if (obj instanceof Promise) {
        return obj.then(resolvedObj=>readProperty(resolvedObj, key))
  }
  if (key === 'size') return readSize(obj)
  if (key === 'first') return readFirst(obj)
  if (key === 'last') return readLast(obj)
  return obj[key]
}
0reactions
harttlecommented, Nov 29, 2020

Then it’s a bug, we should fix it. Thank you for your work!

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery Deferred and promise - Error: Object doesn't support ...
I've got the first deferred method built and the console log shows that it completes, but then I get "Error: Object doesn't support...
Read more >
Promise - JavaScript - MDN Web Docs
Creates a new Promise object. The constructor is primarily used to wrap functions that do not already support promises.
Read more >
JavaScript Promises – The promise.then, promise.catch and ...
A promise is an object in JavaScript that will produce a value sometime in the future. This usually applies to asynchronous operations.
Read more >
Runtime and compile-time metaprogramming - Apache Groovy
This way of using methodMissing does not have the overhead of invokeMethod and is not expensive from the second call on. 1.4. propertyMissing....
Read more >
JavaScript Promises by james-priest
“The Promise object is used for deferred and asynchronous computations.” ... Note: the JavaScript engine does not immediately stop executing this function ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found