|
This is a bit Webpack/React specific, but I've been using CSS Modules with Webpack's css-loader. The two biggest features of this (to me) are: 1) locally scoped styles 2) composable styles. I've been using it a lot this week and being able to write styles without even having to think twice how it might conflict with styles someplace else is just magic, as well as being able to make CSS classes that are as composable as, well, React components. I really feel like something like this is where styling for the web is headed in the long term. Being able to use Sass on top of that is just the cherry on top (and really highlights how great Webpack is).
|
# ? Jun 26, 2015 09:09 |
|
|
# ? Apr 23, 2024 13:02 |
|
I already use SCSS. I was thinking more in the way the CSS is structured. CSS Modules looks like the right sort of thing! thanks
|
# ? Jun 26, 2015 09:56 |
|
Angular (1.4) question: Say I have a page with a menu on top and content below. They each have their own controller. (Not nested.) Sometimes the content is a form where users can edit some things. The 'save changes' button for this should appear in the menu bar. Said button should somehow call the save() method of the content controller. Any ideas on how best to do this? I tried it with broadcast but couldn't get it work yet. (Because I was operating under the assumption that the content controller was nested in the menu controller.) But even if/when I get that to work, I feel that broadcasting/and or emitting events isn't the best way to achieve this anyway. Would using some kind of service be a good idea? The service would be injected in both menu and content controller, and the menu controller would call poo poo on the service and the content controller can react to it. Or is that stupid? Or is the entire setup stupid?
|
# ? Jun 26, 2015 12:15 |
|
uXs posted:Angular (1.4) question: If you have a central service which your main controller saves all it's data to all the time, and the menu controller then is the one which calls 'save'(which sends to DB) on the service, this will work, but it really depends on your application particulars how well. A few other ways. 1. Broadcast/emit will work. You need to either emit up to the $rootScope, then broadcast back down, or include $rootScope in your menu controller and broadcast straight down from it. 2. Use a pub/sub message bus library like Amplify or Postal to talk between controllers. This is functionally the same as broadcast/emit, but it's a lot easier to abstract away into a service with your own syntax. I would suggest this route. 3. Don't do this, but you CAN grab references to other controllers with the $controller service. You can then have one controller directly call another controllers methods. But this is a bad idea and you shouldn't do it. Edit: I made a post a few pages back about doing #2 with Typescript for strongly typing such a message bus service, if interested. Skandranon fucked around with this message at 15:44 on Jun 26, 2015 |
# ? Jun 26, 2015 15:35 |
|
I did it with this:code:
code:
code:
Second is the controller with the save() function, that registers a callback to it with the service. (And removes it on destroy.) And third is where I define the directive. I can use it by putting 'on-save-click=""' on a hyperlink tag. I like it, it looks clean.
|
# ? Jun 26, 2015 15:58 |
|
uXs posted:I did it with this: This is basically #2, except you wrote your own version of AmplifyJS, that only handles one type of event. If you plan to scale beyond this one use case, I'd suggest using Amplify, and use your Angular service to wrap around it. Also, use BindToController & ControllerAs in your directives, and don't use $scope anymore for your functions or variables, will make things even cleaner.
|
# ? Jun 26, 2015 17:40 |
|
Skandranon posted:This is basically #2, except you wrote your own version of AmplifyJS, that only handles one type of event. If you plan to scale beyond this one use case, I'd suggest using Amplify, and use your Angular service to wrap around it. Ok cool, thanks, I'll try all of that.
|
# ? Jun 26, 2015 17:49 |
|
Heisenberg1276 posted:I already use SCSS. I was thinking more in the way the CSS is structured. CSS Modules looks like the right sort of thing! thanks Take a look at Harry Robert's inuitcss. You build your own modular CSS on top of his experience. I've found it to be very good. Google his CSS guidelines also. Things like Compass and Bourbon are near obsolete nowadays in my opinion due to Autoprefixr handling vendor prefixes which seemed to make up the majority of the mixins provided.
|
# ? Jun 26, 2015 19:31 |
|
Yeah. Don't use Mixin libraries for prefixing, it's a poor use of what you should be using mixins/extends for, reusing patterns and design constructs specific to your project.
|
# ? Jun 27, 2015 08:27 |
|
I have an angularjs directive that has some scope functions and some parser/formatter functions. It seems the ctrl (4th parameter of the linking function) object is different in the scoped functions than in the parser functions. what gives? here's a rough examplecode:
|
# ? Jun 30, 2015 17:26 |
|
an skeleton posted:I have an angularjs directive that has some scope functions and some parser/formatter functions. It seems the ctrl (4th parameter of the linking function) object is different in the scoped functions than in the parser functions. what gives? here's a rough example I'm not sure what you are asking, so I'll just give a run down of how link functions work and maybe hit what you are looking for. To start, your link functions should be named better. The first three parameters are supposed to be "scope, element, attrs", as they are populated with the directives $scope, the element the directive is attached to, and an array of HTML attributes on that element. The fourth parameter is optional, which can either be a single Controller, or an array of Controllers. This is determined by the directive definition "require" field. If multiple directives are listed here, the controllers from all of them will be included as an array. If nothing is specified, the controller specified for that directive will be there (if there is one). Also, it's pretty bad practice to be adding functions to the scope in the link function. If you want to add functions to the scope that the template or controller is going to call, put it in the Controller. The link function should only be about manipulating DOM elements (using jQuery and such). For that matter, use bindToController and controllerAs in your directive, and keep your functions in the Controller object altogether. Skandranon fucked around with this message at 18:15 on Jun 30, 2015 |
# ? Jun 30, 2015 18:13 |
|
ReactEurope are streaming their conference, if that interests you. There'll probably be a few interesting updates on new projects (crossing my fingers for Relay) on top of everything else: https://www.youtube.com/watch?v=UclvvqNtNNo
|
# ? Jul 2, 2015 09:59 |
|
WORLDS BEST BABY posted:ReactEurope are streaming their conference, if that interests you. There'll probably be a few interesting updates on new projects (crossing my fingers for Relay) on top of everything else: Thanks, this is great! e: Very cool thing referenced in stream: Dan Abramov's React List Kekekela fucked around with this message at 11:22 on Jul 2, 2015 |
# ? Jul 2, 2015 10:54 |
|
Got a simple question about Sublime that i'm hoping you fellas could answer for me! I recently installed the Emmet package in Sublime to help speed up my work flow, but for some reason I can't seem to get the most basic keystroke shortcut to work for me. It's the simple one where you type "!" followed by the TAB key, resulting in a basic HTML template. I don't know why, but typing the "!" character followed by a TAB key doesn't create the HTML template like it should. Am I doing something wrong here? I know the package is installed correctly because typing something like "lorem" followed by the TAB key results in a paragraph of lorem ipsum, but for some reason or another the template shortcut doesn't work. This is one of those shortcuts that shaves off a buttload of gruntwork time, and i'd like to get this working correctly! P.S. - For the record, the documentation has already been changed from plain text to HTML, so it's not a simple matter of picking the right syntax. Any suggestions?
|
# ? Jul 2, 2015 16:51 |
|
Try ctrl/cmd + e, instead of tab.
|
# ? Jul 3, 2015 00:44 |
|
I thought I was finally up to speed on front end development, but I just found a ton of newer stuff this week that I'm not familiar with. Anyone care to chime in on their thoughts and usage of these two things? 1) Polymer/Web Components - Polymer seems like just some polyfills for compartmentalized stuff so you can easily re-use common ones, and you get the isolation that only iframes currently provide. These sound great, but browser support seems to be lacking and doesn't appear to be converging towards an accepted standard. 2) Function reactive programming/ClojureScript/Om/Rxjs/etc - Observables and Clojure and a bunch of things I don't understand at all. Why would you want to compile Clojure down to Javascript? Why is MVC horrible and reactive programming something more than hype?
|
# ? Jul 3, 2015 18:48 |
|
Helicity posted:I thought I was finally up to speed on front end development, but I just found a ton of newer stuff this week that I'm not familiar with. Anyone care to chime in on their thoughts and usage of these two things? Yeah that seems about right. I'm not sure something like Polymer would really add that much in the future anyway since modern view libraries already work with everything in terms of small components. It's just that now they get thrown together in to one big mess, and when web components get wide support the same components will be nicely packed together and work the exact same. quote:
People have a truly amazing capacity for hating javascript and refusing to work with it at all, which is why we now have things like Scala compiling to javascript, and Python compiling to javascript, and haskell compiling to javascript, and now a big push for C++ to javascript for some reason. Now Clojure does seem like a good language and the ClojureScript community seems pretty good at providing a good environment (going mostly off of following David Nolen on twitter). Some people just like Clojure and would like to use that instead of javascript. quote:
MVC probably isn't horrible. MVC itself is really just a name that has been applied to countless variations on the same concept of user interaction architectures over the years that all take the same general name but are slightly different. The promise of reactive programming is to make codebases cleaner and easier to work with by reducing the amount of state and deep interactions. Instead everything is modeled as [input] -> stateless processing -> [output], with the inputs and outputs being things that listen to and publish on streams. I think reactive is becoming noticed a lot more right now because people in general are turning away from old Java style OOP patterns to functional programming, and since javascript and UI in general so well suits reactive programming (since so much of the driver behind what web codebases do is events and waiting for events to happen and then setting off more events) that it's becoming a big storm of people wanting to try out reactive programming as much as possible. Also React and Flux fueled that fire in a way since React suits immutability so well, and Flux is just an architecture that is nothing but events and suits immutability so well again.
|
# ? Jul 4, 2015 01:31 |
|
Helicity posted:Our main solution has 87 projects Jesus christ.
|
# ? Jul 4, 2015 01:38 |
|
AuxPriest posted:Jesus christ. We're a top 500 website that's part of an international media conglomerate and we have a lot of pages that do a lot of different things for a lot of different people. Our biggest concern is serving up news articles but there's lots more. Also, to be fair, some of those projects are cruft from before .NET MVC supported "areas" in a useful way. Thanks for the good answers. I'll probably try to solve one of our common use cases in ClojureScript/Om or something and see what it gets me.
|
# ? Jul 4, 2015 02:44 |
|
Videos from the ReactEurope conference will start being posted tonight here. Also, I just wanted to highlight this amazing issue raised on the reddit issue tracker: https://github.com/reddit/reddit-mobile/issues/247 Thermopyle fucked around with this message at 19:37 on Jul 4, 2015 |
# ? Jul 4, 2015 19:25 |
|
Thermopyle posted:Videos from the ReactEurope conference will start being posted tonight here. Excellent, I caught a few of the presentations on the live stream but at some point the audio got out of sync and I couldn't gut it out any further. quote:Also, I just wanted to highlight this amazing issue raised on the reddit issue tracker: https://github.com/reddit/reddit-mobile/issues/247 Haha, I was just reading this before checking the thread :fistbump:
|
# ? Jul 4, 2015 19:42 |
|
Does anyone know if there's a way in Babel or Webpack (or babel-loader for Webpack) to define imports in terms of a project root instead of having tons of '../../../fart/butt' import definitions everywhere? I looked through the Babel options but nothing is too helpful since the promising ones only have one vague line telling you what it does.
|
# ? Jul 5, 2015 00:09 |
|
piratepilates posted:Does anyone know if there's a way in Babel or Webpack (or babel-loader for Webpack) to define imports in terms of a project root instead of having tons of '../../../fart/butt' import definitions everywhere? That sounds like resolve.modulesDirectories.
|
# ? Jul 5, 2015 00:16 |
|
substitute posted:Try ctrl/cmd + e, instead of tab. Hrm, that's not doing anything either : ( This really is puzzling! It's bizarre, every other shortcut works just fine, it's only the "!" character that does nothing, both using TAB and with the above method. White Light fucked around with this message at 18:09 on Jul 6, 2015 |
# ? Jul 6, 2015 18:05 |
|
Parrotine posted:Hrm, that's not doing anything either : ( Well I guess double-check the default Sublime shortcuts and the User shortcuts to see if there's an overlap.
|
# ? Jul 7, 2015 07:28 |
|
I need some Angular help because I don't know what I'm doing. A couple of developers started using Angular and I was tasked with fixing a bunch of the bugs. One page has a left hand side panel with a list of master-child items (say Foos with a list of Bars attached). When you click on a bar the UI on the right will show more information and the selection is saved in $scope.bar. There's an edit button, when clicked will show a modal edit form using an ng-click attribute that calls a showEditBar on the Controller passing vm.$scope.bar into it. The function sets a variable for the object being edited ($scope.barToEdit) and sets a boolean to show the modal edit window. Hit the save button which calls a function on the Controller (updateBar) and passes in barToEdit which calls Put on a Service that returns a Promise using $q to wrap the $http promise. Inside the Then I'm trying to set the data from the JSON API to $scope.bar, things aren't quite right. The slide out panel has the updated information but the list on the left hand side isn't updated. If I use angular.extend($scope.bar, data) that updates everything correctly. I understand why angular.extend is working because the function is copying all of the data over, but I don't understand why direct assignment isn't. Is it because Angular doesn't know anything about the new object?
|
# ? Jul 7, 2015 18:55 |
|
gariig posted:I need some Angular help because I don't know what I'm doing. A couple of developers started using Angular and I was tasked with fixing a bunch of the bugs. One page has a left hand side panel with a list of master-child items (say Foos with a list of Bars attached). When you click on a bar the UI on the right will show more information and the selection is saved in $scope.bar. There's an edit button, when clicked will show a modal edit form using an ng-click attribute that calls a showEditBar on the Controller passing vm.$scope.bar into it. The function sets a variable for the object being edited ($scope.barToEdit) and sets a boolean to show the modal edit window. Hit the save button which calls a function on the Controller (updateBar) and passes in barToEdit which calls Put on a Service that returns a Promise using $q to wrap the $http promise. Inside the Then I'm trying to set the data from the JSON API to $scope.bar, things aren't quite right. The slide out panel has the updated information but the list on the left hand side isn't updated. If I use angular.extend($scope.bar, data) that updates everything correctly. It's a little hard to follow what is going on from your description (as opposed to actual code or pseudo-code), but one thing to check is if the variable is not being set at ALL, or is just not being displayed. Put some console.logs in to show when it's updated and the new value, and see if the screen reflects it. If the variable is being updated, but not shown on the screen, it's an issue with your digest cycle. Edit: To elaborate, angular.extend is probably working for different reasons than you think. If you are just setting bar.baz=1, and your $watch is set to bar, it won't notice that .baz has changed. When you use angular.extend, it is creating an entirely new object and assigning it to bar, which is what $watch is looking for (memory reference change on Objects, or value changes on primitive types). This explains the different kinds of $watches and how they do(or don't) work. http://teropa.info/blog/2014/01/26/the-three-watch-depths-of-angularjs.html Skandranon fucked around with this message at 19:55 on Jul 7, 2015 |
# ? Jul 7, 2015 19:48 |
|
OK the different type of $watch is definitely what's getting me. Here is some of the code that is being used, I think this is everything that is needed. So the ng-repeat is using a Collection Watch but I'm modifying an individual item which it's not seeing on the master-detail listing side. The more details panel on the right is using a Reference Watch so that's why the angular.extend() is working. As a dirty fix is attaching a By Value watch to $scope.Foos a valid fix? Should I try finding the Bar I editing in the array of Bars and replace with the new one? I don't think that would allow the slide out panel to update. I guess I could change both the Bars array and the BarToMod with the new item. Would that be the most Angular way to fix this? Display of master-detail records code:
code:
code:
code:
code:
|
# ? Jul 7, 2015 20:39 |
|
gariig posted:OK the different type of $watch is definitely what's getting me. Here is some of the code that is being used, I think this is everything that is needed. So the ng-repeat is using a Collection Watch but I'm modifying an individual item which it's not seeing on the master-detail listing side. The more details panel on the right is using a Reference Watch so that's why the angular.extend() is working. Using a ByValue $watch is very expensive, not usually a good way to go. You also want to avoid creating completely new Bar objects, as this will force Angular to create/destroy whole new DOM elements which is probably not necessary. If I am reading your code right, your problem is not updating from within your this.BarService.put(Bar).then() promise. You could wrap that chunk of code in a $scope.apply(), which will make sure to call a $digest on $rootScope once the code contained within runs. This is preferable to using a Value watch, as the digest only happens after a specific change takes place, instead of the Value watch checking every field every $digest. code:
|
# ? Jul 7, 2015 21:38 |
|
Skandranon posted:Using a ByValue $watch is very expensive, not usually a good way to go. You also want to avoid creating completely new Bar objects, as this will force Angular to create/destroy whole new DOM elements which is probably not necessary. If I am reading your code right, your problem is not updating from within your this.BarService.put(Bar).then() promise. You could wrap that chunk of code in a $scope.apply(), which will make sure to call a $digest on $rootScope once the code contained within runs. This is preferable to using a Value watch, as the digest only happens after a specific change takes place, instead of the Value watch checking every field every $digest. OK I tried calling $scope.$apply() and now I'm getting JS Error posted:[$rootScope:inprog] $digest already in progress code:
|
# ? Jul 7, 2015 22:48 |
|
There doesn't seem to be anything wrong with that service call, though you could avoid using $q.defer altogether since $http.put() is already returning a promise. Also, what's with the var self=this? If you want a closure to be created for that method, just use => syntax for the function and TypeScript will handle the that=this pattern for you.code:
I've seen worse ways to use Angular, so don't feel too badly about the state of the code base. Edit: If you want to PM me more I can maybe help further, hard to track down digest issues with just fragments. Skandranon fucked around with this message at 23:47 on Jul 7, 2015 |
# ? Jul 7, 2015 23:44 |
|
Thanks for the answer earlier, Skandranon. I typed out a longish reply to you but somehow it got lost in the Aether. Nonetheless, your advice was helpful. I have another angular issue though -- I have a field (Angular UI Datepicker) that is always being marked as ng-invalid-required, in other words it is failing the required validation, gaining both "ng-invalid" and "ng-invalid-required" classes and messing up validation for the page, which involves submission being disabled if any field is invalid. If I remove the ng-required attribute, the field validates just fine. All the other datepickers (there are a lot in the app), required or not, work fine, except a small subsection of them in this page.
|
# ? Jul 10, 2015 17:21 |
|
an skeleton posted:Thanks for the answer earlier, Skandranon. I typed out a longish reply to you but somehow it got lost in the Aether. Nonetheless, your advice was helpful. I'd start with dumping out field.value and field.$viewValue somewhere to see if anything looks funky. I've had weird validation problems on datepickers because of the wrong format being applied to the value, etc. So if value is like '07/04/2015' and $viewValue is showing like: '2015-07-04' then adjust. Try to use the ISO 8660 format whenever possible, then don't covert until you absolutely need to.
|
# ? Jul 10, 2015 18:32 |
|
I figured it out, though it still doesn't really make sense to me. I have some $formatter code, that is parsing the date value. code:
code:
|
# ? Jul 10, 2015 20:33 |
|
I've been asked by a coworker to take a look at an online application form our clients use that is rather user unfriendly and apparently has a high rate of abandonment before completion. It's written in vanilla JS and is spread across several pages. He wants me to mock up a more modern version that's easier to use and fully responsive. I was going to just make something simple with JS and a better design, but I want to try using one of the more modern frameworks. Since I'm doing this as a favor and not writing anything that will actually be deployed to the wild, I'm not worried about having production-quality code in the first version. Any recommendations for the best tool here? I'm leaning towards Angular, as it seems to have robust form validation built in and two-way data binding seems enormously useful for forms.
|
# ? Jul 11, 2015 08:46 |
|
You think you could write a program that could follow the lyrics of Rapper's Delight? I know you could use an if/else statement for part of the middle section: if (girlActingUp) {currentSpeed--;} then {System.error.println("Take her friend")} Something like that
|
# ? Jul 11, 2015 11:48 |
|
my bony fealty posted:He wants me to mock up a more modern version that's easier to use and fully responsive. [...] I'm leaning towards Angular, as it seems to have robust form validation built in and two-way data binding seems enormously useful for forms. Perhaps try out KnockoutJS. You can tack on PagerJS if you want to make it more of a client-side app with routing, rather than just a one-page tool. I wouldn't say there's a "Best tool" in that sense, it's always tool-for-a-job. If you've got a few hours to waste, follows the starter tutorials for each (Angular, Knockout, React) and see what you think is most useful for your use case, and/or doesn't make you want to stab yourself.
|
# ? Jul 11, 2015 15:05 |
|
my bony fealty posted:I've been asked by a coworker to take a look at an online application form our clients use that is rather user unfriendly and apparently has a high rate of abandonment before completion. It's written in vanilla JS and is spread across several pages. He wants me to mock up a more modern version that's easier to use and fully responsive. I was going to just make something simple with JS and a better design, but I want to try using one of the more modern frameworks. Since I'm doing this as a favor and not writing anything that will actually be deployed to the wild, I'm not worried about having production-quality code in the first version. Simple forms applications are what Angular was really designed to handle. I wouldn't worry about Angular 2.0 coming out, it's still at least 6 months out, and the 1.x line will be supported for at least 2 years after 2.0 comes out. Also, if you use something like Typescript, you can do your Angular 1.x app in a way that makes transitioning easier.
|
# ? Jul 11, 2015 17:27 |
|
I may need to hit up the JS thread, but would d3js be the easiest/fastest way to visually display backend data? We typically use Tableau/ReportingServices with SQL Server/cubes, but I'd like to delve more into the webapp/front-end side and learn something new.
|
# ? Jul 11, 2015 19:20 |
|
|
# ? Apr 23, 2024 13:02 |
|
kloa posted:I may need to hit up the JS thread, but would d3js be the easiest/fastest way to visually display backend data? The "fastest" way to "visually display" backend data is to dump the data as an HTML table to the browser; no JS needed. What kind of data do you have, and what do you want to visualize about it? If you just want to do bar/line graphs, D3 is too low-level.
|
# ? Jul 11, 2015 19:27 |