|
A return value of false in the filter callback removes that entry, true keeps it. So if the key is set on the object you return false, otherwise true (which is also the seen value, to combine the condition and return into a single statement).
|
# ? Apr 29, 2018 19:42 |
|
|
# ? May 15, 2024 05:17 |
|
Revalis Enai posted:]This looks interesting, but I don't think I'm able to utilize it since I work mostly with Google Apps Script, and apparently using libraries can be slow. Use Webpack to compile a bundle including all dependencies and any necessary polyfills.
|
# ? Apr 29, 2018 23:41 |
|
Revalis Enai posted:Wow, the code got exactly what I was looking for and it ran fast. I'm trying to figure out how it actually does the filtering. From what I understand it's going through every item code(item[1]) to see if the object has its own property? If true, then it's set to false, and if false, it does (seen[k] =true), which I'm not sure what that does. So the deal is array.filter will return the items in the array that pass the test, and exclude the ones that fail. e.g. code:
So what we're really trying to do is "exclude all elements in the array that have already been seen." "Seen" is an object containing keys that already been used. It starts empty, but as items with keys are found, the keys will be added to the Seen object, and anything with a key that has already been added to the seen object so it won't pass the filter. code:
1. Get the key of the object (if you want to do whole object comparison, you could just JSON.stringify the object here). 2. If the object has not been 'seen', then it passes the test - but we add its key to the 'seen' object. 3. If the object has been seen, exclude it from the returned array.
|
# ? Apr 30, 2018 01:57 |
|
I don't want it to be pointlessly difficult to notice what's below that div just because the webpage deceives the visitor into thinking they've hit the page bottom. e: Nevermind, I was imagining it. If the mouse happens to be over the child when the parent scrollbar bottoms out, *then* the child will start scrolling, but at no point does the child steal scrolling focus first and obscure that there's more on the page. Happy Thread fucked around with this message at 03:51 on May 4, 2018 |
# ? May 4, 2018 02:43 |
|
Are there any dumb, hacky ways to dynamically register a component in Angular 1 without declaring a module? I'm converting an existing codebase to use a Webpack build and explicit imports for everything, and I've got AppHeader and AppNavigation components that I want to use in an App component without either (a) doing angular.module(APP_MODULE_NAME).component(...) inside the files (it would probably break stuff anyway given import hoisting) or (b) exporting them multiple layers down and having every single component I want to use declared in a root index.js. Edit: Maybe some way to nest routes with ngRoute or ui-router so I can have all the generic stuff populate off /? I find it bizarre that none of the route stuff requires explicitly pre-registered components/directives when everything else does. Edit edit: I really just want some straightforward way to attach more components to a root-level App component, though, so I can use <whatever-component></whatever-component> tags in the template files without polluting other areas of the code. Roadie fucked around with this message at 01:44 on May 5, 2018 |
# ? May 5, 2018 01:37 |
|
when ur js framework is a baby project and u dont know how to document it or point out what it does or why its better or really anything about why other js frameworks are good but u make 1 anyway and just use a bunch of programming words to make it seem good: https://dojo.io
|
# ? May 6, 2018 20:34 |
|
Ape Fist posted:when ur js framework is a baby project and u dont know how to document it or point out what it does or why its better or really anything about why other js frameworks are good but u make 1 anyway and just use a bunch of programming words to make it seem good: dojo was one of the very first "frameworks" along with prototype and was all the rage until that young whippersnapper jQuery came out. Not sure why they felt the need to make another one, but they continued the tradition of pre-jQuery things by having docs that were made for people who already fully understood them. One of the big reasons jQuery got so drat popular is that it's docs were / are AWESOME.
|
# ? May 7, 2018 16:52 |
|
Anybody ever seen a scrollbar go grey (and unresponsive) on a child element when there is clearly overflowing content inside of it? Outer box is set to "overflow:auto; width: 200px" and there's no other style the spans inside it would have inherited besides a "font-family: monospace"
|
# ? May 8, 2018 00:13 |
|
How would you go about creating a graph like this one from some json data: This is something i made from this d3 example I tried changing some values after browsing the docs but it either does nothing or breaks the graph. Basically I'd like to have labels, bigger nodes and longer edges, and can't write js to save my life. Current code. There's a separate JSON file. e: this could be what I'm looking for. unpacked robinhood fucked around with this message at 11:50 on May 9, 2018 |
# ? May 9, 2018 10:49 |
|
I have an existing Angular 4 app, that was upgraded from Angular 2 before the cli existed. It is still running System JS. I now have business reasons to switch to webpack. Is least painful way to do this to create a new project with the cli then copy my app folder and package.json files?
|
# ? May 9, 2018 15:40 |
|
unpacked robinhood posted:How would you go about creating a graph I'm not sure if there's a good off-the-shelf solution for it. It's relatively easy to generate SVG, though, so if you can find the right algorithm you could generate the markup yourself
|
# ? May 9, 2018 18:17 |
|
Calidus posted:I have an existing Angular 4 app, that was upgraded from Angular 2 before the cli existed. It is still running System JS. I now have business reasons to switch to webpack. Is least painful way to do this to create a new project with the cli then copy my app folder and package.json files? Never, ever write a Webpack config yourself. It will suck up days of your life just trying to figure out simple crap like "how do I get this other random import type to work with the dev server".
|
# ? May 10, 2018 06:57 |
Roadie posted:Are there any dumb, hacky ways to dynamically register a component in Angular 1 without declaring a module? I'm converting an existing codebase to use a Webpack build and explicit imports for everything, and I've got AppHeader and AppNavigation components that I want to use in an App component without either (a) doing angular.module(APP_MODULE_NAME).component(...) inside the files (it would probably break stuff anyway given import hoisting) or (b) exporting them multiple layers down and having every single component I want to use declared in a root index.js. In angular 1 it's directives, not components, right? You just register those on your app's main module call with .directive. Either define them as part of the call or require them.
|
|
# ? May 10, 2018 11:58 |
|
Roadie posted:Never, ever write a Webpack config yourself. It will suck up days of your life just trying to figure out simple crap like "how do I get this other random import type to work with the dev server". Or, spend an hour understanding how webpack works and then its not hard.
|
# ? May 10, 2018 15:30 |
|
Dumb Lowtax posted:Anybody ever seen a scrollbar go grey (and unresponsive) on a child element when there is clearly overflowing content inside of it? I encountered this again in a similar application and think I figured something out. It seems that the scrollbar appears (but is erroneously disabled) when I use a javascript loop to go in and add a bunch of spans or table rows inside an existing div (nested inside another fixed-size div or frame). It's as though the width/height of the contents isn't updating the width/height of the inner div correctly, causing the outer one's scrollbar to bug out and be grey. I manually entered a comically big inner div width and height in the other application and it successfully forced the scrollbar to exist before the javascript fires, so I guess I'll try that here too. A stupidly oversized inner div is better than not being able to scroll enough to see all of a normal sized one. Happy Thread fucked around with this message at 18:29 on May 10, 2018 |
# ? May 10, 2018 18:00 |
|
Osmosisch posted:In angular 1 it's directives, not components, right? You just register those on your app's main module call with .directive. Either define them as part of the call or require them. Components are supported starting in 1.5, and available as far back as 1.3 with the angular-component backport.
|
# ? May 10, 2018 18:17 |
|
Osmosisch posted:In angular 1 it's directives, not components, right? You just register those on your app's main module call with .directive. Either define them as part of the call or require them. Spraynard Kruger posted:Components are supported starting in 1.5, and available as far back as 1.3 with the angular-component backport. The point in this case is that I want to find some way to use component A in component B without having to manually register component A on the app module. tl;dr gently caress angular, global everything sucks
|
# ? May 11, 2018 02:19 |
|
Roadie posted:The point in this case is that I want to find some way to use component A in component B without having to manually register component A on the app module. Components must be registered in a module, you can't have hanging components. Why are you trying to avoid registering it with the app module?
|
# ? May 11, 2018 03:14 |
|
Skandranon posted:Components must be registered in a module, you can't have hanging components. Why are you trying to avoid registering it with the app module? It offends me to treat nested components as a global dependency.
|
# ? May 11, 2018 19:11 |
|
Roadie posted:It offends me to treat nested components as a global dependency. I haven't done angular in so long to know if this is good in this specific instance, but I just wanted to say that I approve of cultivating this attitude.
|
# ? May 11, 2018 19:24 |
|
Roadie posted:The point in this case is that I want to find some way to use component A in component B without having to manually register component A on the app module. If component B is in the app's root module, and component B needs to use component A, then component A needs to either be in the root module too, or be in one of the root module's dependency modules. You've said you don't want to put component A in the root module, that's fine. But you've also said you don't want to declare some new dependency module for component A to be in, because this would break things. So I'm not aware of any way to do what you're asking for. I'm not really sure if I understand what you're asking for.
|
# ? May 11, 2018 22:10 |
|
Roadie posted:It offends me to treat nested components as a global dependency. You have 3 options for organizing your components in AngularJS. 1. You put all your components into your root module. All components can be used anywhere. 2. You create a hierarchy of modules, and you place the components in the appropriate module. You then reference those modules in your main module, and AngularJS adds everything to that main module. All components can be used anywhere. 3. Do something insane with meta-programming and custom compilation which boils down to 1 or 2. If this still offends you, don't use AngularJS and use Angular or Vue or React.
|
# ? May 11, 2018 22:20 |
|
I'm pretty good at .map, .filter, and .reduce, but I have to manipulate an array in a particular way and I'm not sure what the best smartest way to do it would be. Lets say I have an array: ['foo', 'foo', 'foo', 'bar', 'foo', 'bar', 'foo']; Now I want to return a copy of the array starting from the beginning, up to the first instance of 'bar'. So the copy of the array I'd want would look like this: ['foo', 'foo', 'foo', 'bar'] Now a few considerations, I have no idea if 'bar' ever exists in the array, in teh case that it doesn't I want an empty array (or some other flag). This doesn't seem to work for filter, because filter doesn't really care about order as far as I am aware. Reduce also doesn't really track order inherently.
|
# ? May 17, 2018 20:29 |
|
indexOf and slice it out.code:
|
# ? May 17, 2018 20:44 |
|
necrotic posted:indexOf and splice it out. Sorry, imagine the array is actually complex objects such that indexOf would not work.
|
# ? May 17, 2018 20:45 |
|
Those array traversal shorthand functions are very useful but I don't think they're meant to replace everything an array can do, but rather supplement it. The other simpler functions (slice, indexOf) still have their jobs to do and this sounds like it doesn't call for anything more. In your case this does the trick:code:
|
# ? May 17, 2018 20:46 |
|
Knifegrab posted:Sorry, imagine the array is actually complex objects such that indexOf would not work. So you aren't finding "bar" you're looking for eg "some.nested.data"?
|
# ? May 17, 2018 20:47 |
|
I'd just bust out a for loop here.code:
|
# ? May 17, 2018 20:49 |
|
necrotic posted:So you aren't finding "bar" you're looking for eg "some.nested.data"? Yes. necrotic posted:I'd just bust out a for loop here. Yeah this is probably the best approach I just hate using for loops in modern js
|
# ? May 17, 2018 20:50 |
|
Knifegrab posted:Yes. for loops are still 100% acceptable in "modern javascript", exactly for situations like this.
|
# ? May 17, 2018 20:51 |
|
necrotic posted:for loops are still 100% acceptable in "modern javascript", exactly for situations like this. Totally, I know its not a problem I just enjoy never using them :P
|
# ? May 17, 2018 20:58 |
|
Filter and indexOf can work together. Suppose you have this data structure full of unknown objects: [ { i: 'foo' }, { j: 'foo' }, { i: 'foo' }, { i: 'bar' }, 'foo', { j: 'bar' }, 'foo']; And that { i: 'bar' } is the interesting one to you. Specifically, suppose you're only interested in the array up to (and including, hence the +1 below) the first (hence the [0] below) element that has a field "i" with value "bar". This one liner will do the trick, and meets the requirement where an empty array is returned if there's no such element: code:
Happy Thread fucked around with this message at 21:07 on May 17, 2018 |
# ? May 17, 2018 21:04 |
|
Dumb Lowtax posted:Why scroll past a lot more lines than you have to? Because the for loop is more readable.
|
# ? May 17, 2018 21:05 |
|
Thermopyle posted:Because the for loop is more readable. Either one requires you to sit and read through something to figure out what will be returned. Not everyone gets squeamish when the constructs that make them stop, read, think sometimes exist on just one line of a handful of tokens. It's the same amount of thinking regardless, except now you have a lot more room on the screen for a helpful code comment explaining an example that makes it all unambiguously clear.
|
# ? May 17, 2018 21:10 |
|
why use arr.filter()[0] when you could use arr.find? and then replace the arr.indexOf(arr.find) with arr.findIndex arr.slice(0, arr.findIndex((m) => m.thing.junk === "bar")+1)
|
# ? May 17, 2018 21:25 |
|
Dumb Lowtax posted:Either one requires you to sit and read through something to figure out what will be returned. Not everyone gets squeamish when the constructs that make them stop, read, think sometimes exist on just one line of a handful of tokens. It's the same amount of thinking regardless, except now you have a lot more room on the screen for a helpful code comment explaining an example that makes it all unambiguously clear. The constraint in readable code is not the number of lines.
|
# ? May 17, 2018 21:29 |
|
Dumb Lowtax posted:Either one requires you to sit and read through something to figure out what will be returned. Not everyone gets squeamish when the constructs that make them stop, read, think sometimes exist on just one line of a handful of tokens. It's the same amount of thinking regardless, except now you have a lot more room on the screen for a helpful code comment explaining an example that makes it all unambiguously clear. I hope I never work with you. Please don't code-golf at work.
|
# ? May 17, 2018 21:37 |
|
Suspicious Dish posted:why use arr.filter()[0] when you could use arr.find? and then replace the arr.indexOf(arr.find) with arr.findIndex This is not bad, I forgot they added a findIndex. I think I still prefer the looping approach given the need to + 1 the resulting index.
|
# ? May 17, 2018 21:38 |
|
I also forgot about findIndex so my first thought was to map to the nested property and then indexOf that :\
|
# ? May 17, 2018 21:53 |
|
|
# ? May 15, 2024 05:17 |
|
necrotic posted:This is not bad, I forgot they added a findIndex. I think I still prefer the looping approach given the need to + 1 the resulting index. I think with a simple comment like // Retrieve everything up to and including "bar" it can be explained.
|
# ? May 17, 2018 22:22 |