Giter Club home page Giter Club logo

Comments (9)

leebyron avatar leebyron commented on May 3, 2024 2

I like that idea. If anyone is interested in championing this, I would be happy to entertain the PR


Sent from Mailbox

On Tue, Nov 3, 2015 at 2:45 PM, Jarda Kotěšovec [email protected]
wrote:

Sounds good to me. Just having new serializeKey option in DataLoader options, which would be used if available. So by default it still would be comparing by reference and if needed we could pass custom serializeKey function.

Reply to this email directly or view it on GitHub:
#8 (comment)

from dataloader.

zerkalica avatar zerkalica commented on May 3, 2024

+1

Yes, something like this:

const loader = new DataLoader(({phone, id}) => myLoad({phone, id}))

loader.load({phone, id})

from dataloader.

zerkalica avatar zerkalica commented on May 3, 2024

This fix is monkey-patch of global Map. Need to delegate serializeKey in options of dataloader.

import BaseMap from 'core-js/library/es6/map'

function objectToKey(obj) {
    return Object.keys(obj).sort().map(k => k + ':' + obj[k]).join('-')
}

function serializeKey(key) {
    let result
    if (typeof key === 'object' && key !== null) {
        result = Array.isArray(key)
            ? key.map(k => serializeKey(k)).join('-')
            : objectToKey(key)
    } else {
        result = key
    }
    return result
}

class Map extends BaseMap {
    get(key) {
        return super.get(serializeKey(key))
    }

    has(key) {
        const is = super.has(serializeKey(key))
        return is
    }

    delete(key) {
        return super.delete(serializeKey(key))
    }

    set(key, data) {
        return super.set(serializeKey(key), data)
    }
}

global.Map = Map

from dataloader.

leebyron avatar leebyron commented on May 3, 2024

Hmm, there are also cases where Objects (including Arrays) are used as identifying keys by reference. I certainly wouldn't want to also break that use-case.

Do you have a proposal for how we should differentiate between these cases? Also, this library's goal is to be singular in focus and with little to no dependencies. What might work for your needs?

from dataloader.

zerkalica avatar zerkalica commented on May 3, 2024

Just extract cache key generating strategy from dataloader and allow to programmers define they own strategies.

from dataloader.

jardakotesovec avatar jardakotesovec commented on May 3, 2024

Sounds good to me. Just having new serializeKey option in DataLoader options, which would be used if available. So by default it still would be comparing by reference and if needed we could pass custom serializeKey function.

from dataloader.

zerkalica avatar zerkalica commented on May 3, 2024

Any progress?

from dataloader.

leebyron avatar leebyron commented on May 3, 2024

I will dig into this soon, thanks :)

from dataloader.

CatTail avatar CatTail commented on May 3, 2024

Any progress?

from dataloader.

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.