Code Monkey home page Code Monkey logo

Comments (4)

olosegres avatar olosegres commented on August 26, 2024

Hi, actually Jsona is designed to use circular relationships.

You can look at original implementation here

setRelationships(model: TJsonaModel, relationships: TJsonaRelationships) {

You have few choices:

  • move deserialization somewhere to hook, after raw data is processed by react-query
  • modify process of properties mapping via extending JsonPropertiesMapper and use some special implementation of setRelationships method or defineRelationGetter (jsona is extanable const dataFormatter = new Jsona({ jsonPropertiesMapper: MyJsonPropertiesMapper });)

from jsona.

kcsujeet avatar kcsujeet commented on August 26, 2024

@olosegres thank you for the reply. can you provide an example of how to do this?

from jsona.

olosegres avatar olosegres commented on August 26, 2024

@olosegres thank you for the reply. can you provide an example of how to do this?

To do what? extend jsona? It is briefly described in the readme https://github.com/olosegres/jsona#customize

But I highly recommend you to use my first suggestion - move deserialization from the interceptor to custom hook. Something like useJsonApiFetch where you will get data from api and convert it to deserialized version.

from jsona.

kcsujeet avatar kcsujeet commented on August 26, 2024

For future references:

I was able to solve this problem by changing this line model[propName] = relationships[propName] in setRelationships method. changed it as:

model[propName] = structuredClone(relationships[propName])

Make a separate myCustomMapper.ts where everything is same as link, except for the line mentioned above.

Then just use the custom mapper as:

import { JsonPropertiesMapper } from 'utils/myCustomMapper

const dataFormatter = new Jsona({
  jsonPropertiesMapper: new JsonPropertiesMapper()
})

from jsona.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.