{"action":"created","issue":{"url":"https://api.github.com/repos/planttheidea/moize/issues/53","repository_url":"https://api.github.com/repos/planttheidea/moize","labels_url":"https://api.github.com/repos/planttheidea/moize/issues/53/labels{/name}","comments_url":"https://api.github.com/repos/planttheidea/moize/issues/53/comments","events_url":"https://api.github.com/repos/planttheidea/moize/issues/53/events","html_url":"https://github.com/planttheidea/moize/issues/53","id":244219638,"number":53,"title":"Possible to ignore arguments?","user":{"login":"aduth","id":1779930,"avatar_url":"https://avatars1.githubusercontent.com/u/1779930?v=4","gravatar_id":"","url":"https://api.github.com/users/aduth","html_url":"https://github.com/aduth","followers_url":"https://api.github.com/users/aduth/followers","following_url":"https://api.github.com/users/aduth/following{/other_user}","gists_url":"https://api.github.com/users/aduth/gists{/gist_id}","starred_url":"https://api.github.com/users/aduth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aduth/subscriptions","organizations_url":"https://api.github.com/users/aduth/orgs","repos_url":"https://api.github.com/users/aduth/repos","events_url":"https://api.github.com/users/aduth/events{/privacy}","received_events_url":"https://api.github.com/users/aduth/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-07-20T01:26:22Z","updated_at":"2017-07-20T07:27:17Z","closed_at":null,"body":"I'm working to upgrade Moize to the 3.x line for a [library of mine](https://github.com/aduth/rememo). I'd previously relied on specifying a custom cache as a hack to be able to ignore the first argument passed to the memoized selector.\r\n\r\nSee: https://github.com/aduth/rememo/blob/v1.1.1/es/rememo.js#L18-L66\r\n\r\nSince the `cache` option has been removed as part of the 3.0 changes, I'm seeking an alternative.\r\n\r\nMy first thought was to use the `equals` option, but this function is called with the singular arguments to compare, and it's not possible to know the argument's position.\r\n\r\nI thought too to use `Function#bind` to prepopulate the first argument for the memoized function without moize considering it, but since the value for the first argument changes frequently in my case, I worry about the performance of using `bind`.\r\n\r\nDo you have any recommendations for how I could reimplement this behavior in 3.x ?"},"comment":{"url":"https://api.github.com/repos/planttheidea/moize/issues/comments/316620424","html_url":"https://github.com/planttheidea/moize/issues/53#issuecomment-316620424","issue_url":"https://api.github.com/repos/planttheidea/moize/issues/53","id":316620424,"user":{"login":"planttheidea","id":9438233,"avatar_url":"https://avatars3.githubusercontent.com/u/9438233?v=4","gravatar_id":"","url":"https://api.github.com/users/planttheidea","html_url":"https://github.com/planttheidea","followers_url":"https://api.github.com/users/planttheidea/followers","following_url":"https://api.github.com/users/planttheidea/following{/other_user}","gists_url":"https://api.github.com/users/planttheidea/gists{/gist_id}","starred_url":"https://api.github.com/users/planttheidea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/planttheidea/subscriptions","organizations_url":"https://api.github.com/users/planttheidea/orgs","repos_url":"https://api.github.com/users/planttheidea/repos","events_url":"https://api.github.com/users/planttheidea/events{/privacy}","received_events_url":"https://api.github.com/users/planttheidea/received_events","type":"User","site_admin":false},"created_at":"2017-07-20T07:27:17Z","updated_at":"2017-07-20T07:27:17Z","body":"So ... considering the universality and that I could see someone using this for other use-cases than just your example, I went ahead and added the new `transformArgs` option, which does just as described ... transforms the args prior to being used as a key. Wiith this new option, you could do something like:\r\n\r\n```javascript\r\nconst moized = moize(fn, {\r\n  transformArgs(args) {\r\n    return args.slice(1);\r\n  }\r\n});\r\n```\r\n\r\nMuch simpler and easy to understand, but it benchmarks at around 5.5 million ops / second ... still quite fast, but a huge drop from the targeted example I gave above. A small tweak that is slightly less readable but more performant:\r\n\r\n```javascript\r\nconst moized = moize(fn, {\r\n  transformArgs(args) {\r\n    let transformedArgs = [],\r\n        index = args.length;\r\n\r\n    while (--index) {\r\n      transformedArgs[index - 1] = args[index];\r\n    }\r\n\r\n    return transformedArgs;\r\n  }\r\n});\r\n```\r\n\r\nSame result, but benchmarks at about 16 million ops / sec ... still slower than the targeted example, but 3x faster than `slice`. Not trying to sway one direction or another, just providing options based on what is considered priority for your project (raw speed vs readability).\r\n\r\nLet me know if any of these options give you what you're looking for, and if so then I'll close the issue."}}
{"actor":{"display_login":"planttheidea"}}