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

bean :recursive true and ->clj behaves differently #76

Open
torbjornvatn opened this issue Dec 18, 2019 · 4 comments
Open

bean :recursive true and ->clj behaves differently #76

torbjornvatn opened this issue Dec 18, 2019 · 4 comments

Comments

@torbjornvatn
Copy link

torbjornvatn commented Dec 18, 2019

When I try to interact with the objects returned by the Google Cloud getProjects function I get different results when using ->clj and bean :recursive true

(p/let [[ps] (.getProjects resource #js {:filter "name:uc*"})]
    (->> ps
         (map #(bean % :recursive true)
         first
         cljs.pprint/pprint)))
;; =>
{:metadata
 {:projectNumber "XXXXXXXX",
  :projectId "XXXXX",
  :lifecycleState "ACTIVE",
  :name "XXXXX",
  :createTime "2019-11-28T09:56:03.185Z",
  :parent {:type "folder", :id "1004516592721"}},
 :baseUrl "/projects",
 :parent #object[Resource [object Object]],
 :id "XXXXX",
 :createMethod #object[bound wrapper],
 :methods
 {:create true,
  :delete true,
  :exists true,
  :get true,
  :getMetadata true,
  :setMetadata {:reqOpts {:method "PUT"}}},
 :interceptors [],
 :Promise #object[Promise],
 :restore #object[wrapper],
 :create #object[wrapper],
 :delete #object[wrapper],
 :exists #object[wrapper],
 :get #object[wrapper],
 :getMetadata #object[wrapper],
 :setMetadata #object[wrapper],
 :request_ #object[Function],
 :request #object[wrapper], 
 :requestStream #object[Function]}

vs.

(p/let [[ps] (.getProjects resource #js {:filter "name:uc*"})]
    (->> ps
         (map ->clj)
         first
         cljs.pprint/pprint)))
;; =>
#object[Project [object Object]]

Is this because the objects returned from the Google Cloud library is not "pure" javascript Objects?

I would love to add something to the README about this gotcha, but not sure how to formulate it as I don't really understand the underlying reason for this happening.

@martinklepsch
Copy link

Hey! Can you provide any more detail in what way it behaves differently?

@torbjornvatn
Copy link
Author

I managed to create the issue before I added the description, but now it's there

@mfikes
Copy link
Owner

mfikes commented Dec 18, 2019

I wonder if the object in question is returning false for object?.

@torbjornvatn
Copy link
Author

getProjects returns an array within another array, hence the destructing [ps].
Both the inner array and the individual objects in it return false when I check them with object?
When I log them in plain javascript they look like this:

Project {
    _events: [Object: null prototype] {},
    _eventsCount: 0,
    _maxListeners: undefined,
    metadata: {
      projectNumber: '0000000000',
      projectId: 'xxxxxxxxxxx',
      lifecycleState: 'ACTIVE',
      name: 'xxxxxxxx',
      createTime: '2019-11-28T09:56:03.185Z',
      parent: [Object]
    },
    baseUrl: '/projects',
    parent: Resource {
      baseUrl: 'https://cloudresourcemanager.googleapis.com/v1',
      apiEndpoint: 'cloudresourcemanager.googleapis.com',
      timeout: undefined,
      globalInterceptors: [],
      interceptors: [],
      packageJson: [Object],
      projectId: '{{projectId}}',
      projectIdRequired: false,
      Promise: [Function: Promise],
      makeAuthenticatedRequest: [Function],
      authClient: [GoogleAuth],
      getCredentials: [Function: bound getCredentials],
      getProjectsStream: [Function (anonymous)]
    }

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

3 participants