|
I'm working with Backbone and Coffeescript(very new to both), and am trying to figure out access a collection once it's fetched. Scrubbed code below:code:
|
# ? Apr 30, 2015 18:59 |
|
|
# ? Jun 7, 2024 17:57 |
|
You want to listen to the collection for the 'sync' event, then trigger your method calls after. Though it might make more sense to fetch the collection in the code that normally creates that view instead. On a successful fetch, create that view, and then you know the fetched collection will be available. You could also instantiate a promise (like $.Deferred()) on initialize, resolve it on parse, and use $.when().then() to run code once it's resolved.
|
# ? Apr 30, 2015 21:55 |
|
hedgecore posted:You want to listen to the collection for the 'sync' event, then trigger your method calls after. Though it might make more sense to fetch the collection in the code that normally creates that view instead. On a successful fetch, create that view, and then you know the fetched collection will be available. Listening to the sync event worked pretty much instantly. Thank you!
|
# ? Apr 30, 2015 22:41 |
|
I'm starting an academic program in a week where I'll have ~40 or so classmates whose course loads and schedules overlap almost entirely for about 16 months. I intend to take/publish course notes via github pages and I'm looking for advice in establishing a workflow that A) enables me to write documents in real time (eg, taking notes) and B) makes peer collaboration from the rest of the group as easy as possible. For A), I'm pretty comfortable with quickly banging out raw html with emmit shortcuts and snippets, and I had originally thought that I would go this route. For B), I'm thinking that I can put together a tutorial workflow for Atom or VSCode (cross platform and git integration seem necessary here). Now I'm looking at Jekyll and I expect that it may be the appropriate tool simplify parts of this process. Does Jekyll comb files to produce 'reports' out of the box? Eg, could it produce todo.html (and todo.json) by combing all files for instances of code:
Do any of you have experience with a 'live blogging' workflow? Are there more appropriate tools that I'm not considering?
|
# ? May 5, 2015 18:20 |
|
To anyone playing with jspm - what's the "proper" way of incorporating browser-only React into a project? My first guess was to do a "jspm install react" but that installs the npm module and all the dependencies. Opposed to something like moment where you do "jspm install moment" and you're good to go with a single file. Are you supposed to include the module and all the dependencies and then have gulp look for the dist file and throw that into a build directory or something? That seems like an annoying workflow, so I ended up just downloading react.min.js and loading it manually. What's the point of using a package manager if I have to do that, though?
|
# ? May 6, 2015 18:14 |
|
Hey I just inherited a bunch of old HTML4 emailers. I want to spruce them up but I also heard that CSS is only partially supported on some email clients. What are the guidelines for using CSS in emails?
|
# ? May 6, 2015 20:08 |
|
TheOtherContraGuy posted:Hey I just inherited a bunch of old HTML4 emailers. I want to spruce them up but I also heard that CSS is only partially supported on some email clients. What are the guidelines for using CSS in emails? IIRC, don't. Use inline styles. Srsly. The only email clients with good style support are on mobile phones. Web mail is universally awful. I got a lot of use out of Litmus for email testing.
|
# ? May 6, 2015 20:14 |
|
bartkusa posted:IIRC, don't. Use inline styles. Srsly. Thanks, I'll check Litmus out.
|
# ? May 6, 2015 20:35 |
|
TheOtherContraGuy posted:Thanks, I'll check Litmus out. If I need a newsletter out ASAP I code something up real quick and use this inliner: http://zurb.com/ink/inliner.php
|
# ? May 6, 2015 21:19 |
|
So, I want to get started with React and I think I've got the concepts of how to use it, but I'm not sure if the structure I'm envisioning is the "React way" to do this. Example: I want to make a submission form with components that affect other components. I start with a class for the form itself, and in the "render" section it would have a <form> filled with the individual parts, or groups of parts. I would then make classes for each of the parts (NameField, EmailAddressField, etc) and the collection-type parts (RadioGroup, DateAndTimeField, etc). Finally, I would add the main form class to my page, which would then generate the fields inside. Is this the right way to start? If so, how would I tell one field to affect the other? Do any components that affect each other have to be included in some kind of "container" component in order to be able to reference each other? I'm just so used to using jQuery and referring to things with a combination of ids, classes and searching through child elements. Sorry to be so abstract. I tend to just dive in and figure out what works, but that's gotten me in trouble with Ruby and other languages because I never learned the more efficient and clear ways to do some things, and I want to get started with React on the right foot. Mezzanine fucked around with this message at 15:38 on May 10, 2015 |
# ? May 10, 2015 15:35 |
|
Mezzanine posted:So, I want to get started with React and I think I've got the concepts of how to use it, but I'm not sure if the structure I'm envisioning is the "React way" to do this. Starting with forms in React can be a bit confusing because you want to share the state of components at the bottom with other components in the hierarchy. And to do that, it seems like that state would have to go back up the component hierarchy, which is particularly un-React-like. Ideally you want data to always be flowing down your component hierarchy from a single source of truth at the top in the form of immutable props. React has both controlled and uncontrolled form elements, and in controlled elements (which are preferred) the field always displays its value prop. So you need to capture user input yourself, and have it modify the value passed to the value prop. This sounds like a lot of work for changing the value in a text field, but capturing and managing the values of forms yourself can make common jobs like validation a lot easier in the end. On the React docs they first suggest that you create functions in parent components that are then passed down to their child components as props. The child components then use the passed down function to return user input back to the parent component. This is all right for quick hacks, but it becomes hard to manage once your forms start increasing in complexity. At the bottom of that documentation page they briefly talk about using a global event system instead, and it's a shame they don't go further into it because it's the ideal solution for something like this. With a global event system, your can make your form fields report user input right back to the top of the hierarchy, where an object representing all the state in your form can be modified and then passed back down the hierarchy as immutable props. This is great, because there's now only one stateful component in your form, which will make developing and debugging it a whole lot easier. I can recommend PubSubJS for something like this. Also, consider that some of your form fields (NameField, EmailAddressField) have very similar jobs and may be easy to merge into a single TextField component that can take validation/format errors as props. React really shines when you have highly reusable components available! WORLDS BEST BABY fucked around with this message at 17:08 on May 10, 2015 |
# ? May 10, 2015 17:05 |
|
WORLDS BEST BABY posted:Starting with forms in React can be a bit confusing because you want to share the state of components at the bottom with other components in the hierarchy. And to do that, it seems like that state would have to go back up the component hierarchy, which is particularly un-React-like. Ideally you want data to always be flowing down your component hierarchy from a single source of truth at the top in the form of immutable props. Also, once you start looking at using a global event system, you might as well go ahead and just implement Flux. I'm liking reflux a lot lately, but there's multiple other implementations as well as just using Facebook's own Dispatcher and rolling your own.
|
# ? May 10, 2015 18:00 |
|
PubSub is a really bad road to go down IMO, for things like form data. The way I see it, if you don't have enough weight to warrant using a flux architecture, there's a root component of the form right, build a pure JavaScript state manager object/class thing that gets instantiated at that root component. The state manager keeps the data inside using Immutable JS (http://facebook.github.io/immutable-js/docs/) and has a few methods for changing that data. When a change happens it sends the data to the root component that gets propagated down the tree, along with methods that can change that data. Immutable is good because it makes all the change checks just by using referential equality, which is fast as hell. It also allows you to do cute stuff, for example in order customisation if changing an option would effect the price in a non trivial way, you can calculate after every single step so each button could bear the price change underneath it quite simply. Bit long story short, don't bury the state in your components, get something separated out that contains your state data and contains all the methods for interacting with that state. Keep it isolated entirely from a React component at first so its just pure JS with simple libraries. From there it'll be easier to figure out how you should pass the data and methods around.
|
# ? May 10, 2015 18:55 |
|
Thermopyle posted:Also, once you start looking at using a global event system, you might as well go ahead and just implement Flux. I'm liking reflux a lot lately, but there's multiple other implementations as well as just using Facebook's own Dispatcher and rolling your own. Flux is great, but I thought it might learning about the dispatcher/actions/stores might overkill for someone just getting their bearings with React. I like Flummox a lot myself! Though I wonder whether Flux is going to enjoy the same amount of momentum when Relay finally comes round. Maluco Marinero posted:Bit long story short, don't bury the state in your components, get something separated out that contains your state data and contains all the methods for interacting with that state. Keep it isolated entirely from a React component at first so its just pure JS with simple libraries. From there it'll be easier to figure out how you should pass the data and methods around. Yeah, this is much better! It’s just a little thing, but would you pass the state manager to components further down the hierarchy via props, or use something like context? WORLDS BEST BABY fucked around with this message at 19:41 on May 10, 2015 |
# ? May 10, 2015 19:32 |
|
WORLDS BEST BABY posted:Yeah, this is much better! It’s just a little thing, but would you pass the state manager to components further down the hierarchy via props, or use something like context? I wouldn't, contexts aren't official API yet, so you'd be better off just using props. Something like (snippets from existing code): Trivial state manager with all the complex stuff stripped out: code:
code:
Maluco Marinero fucked around with this message at 00:26 on May 11, 2015 |
# ? May 10, 2015 20:03 |
|
Thanks, everyone! Having the state of the form separated from the components sounds like a good way to start. I'm sure I'll have more questions as I go.
|
# ? May 10, 2015 23:58 |
|
Is there a way to cache certain API requests in Angular? My app provides a list of cities that I want to put in my navbar: `[Denver, Austin, Boston, ...]`. Users can then click on a city and get a list of drop-in hockey venues/dates/times. Ideally, I'd like to populate this navbar and every city's content from the API exclusively. But the navbar data gets refreshed every time the user reloads or changes endpoints (e.g. clicks from Home to Denver). That seems like a lot of calls back to the API just to get a list of cities. My solution so far has been to hard code the list of cities in the navbar code ($scope.cities = ['Denver', 'Austin', 'Boston',...]), which isn't too bad, but I wonder if there's a better or more idiomatic way. In a perfect world, I'd be able to add a new city (and venues) to the database and have users automatically see it. I'm at work, so I don't have any code samples at the moment, but I'm hoping someone can put me on the right track. waffle enthusiast fucked around with this message at 18:54 on May 12, 2015 |
# ? May 12, 2015 18:52 |
|
Dangerllama posted:Is there a way to cache certain API requests in Angular? My app provides a list of cities that I want to put in my navbar: `[Denver, Austin, Boston, ...]`. Users can then click on a city and get a list of drop-in hockey venues/dates/times. Ideally, I'd like to populate this navbar and every city's content from the API exclusively. But the navbar data gets refreshed every time the user reloads or changes endpoints (e.g. clicks from Home to Denver). That seems like a lot of calls back to the API just to get a list of cities. If you have your API calls abstracted out to an external service (should do this anyways), you can then have that service manage a cache instead of always actually making the call. So something like if (hasAlreadyBeenLoaded) resolvePromiseViaCache else resolvePromiseViaAPICall. Your consumers still need to treat the call as a promise, even if resolving from the cache is in fact synchronous.
|
# ? May 12, 2015 20:36 |
|
Oh, I think I understand. So rather than putting logic in my controllers likecode:
code:
|
# ? May 12, 2015 20:52 |
|
Kind of. Your service should be returning promises to your controller, so it can handle accordingly. So in your service, if it's cached, you can use the $q Angular service to create a promise that you resolve immediately. Something like the following. code:
|
# ? May 12, 2015 21:01 |
|
Yeah, makes sense. I've got some reading to do about promises, but it seems pretty straightforward. Thanks for your help.
|
# ? May 12, 2015 21:18 |
|
Dangerllama posted:Is there a way to cache certain API requests in Angular? The sledgehammer approach would be to use HTML5 service workers which pretty much replaces HTML5 appcache because that was rather cumbersome to utilize. MrMoo fucked around with this message at 22:38 on May 12, 2015 |
# ? May 12, 2015 22:34 |
|
Skandranon posted:Kind of. Your service should be returning promises to your controller, so it can handle accordingly. So in your service, if it's cached, you can use the $q Angular service to create a promise that you resolve immediately. Something like the following. Fun fact, you can also use $q.when to simplify this a bit: code:
|
# ? May 12, 2015 23:43 |
|
I wound up consolidating it like so. Since the $http service has its own caching layer, I didn't have to worry about an if/else. Not sure if this is idiomatic but it seems to work (boilerplate from angular-fullstack:service):code:
|
# ? May 13, 2015 15:36 |
|
Dangerllama posted:I wound up consolidating it like so. Since the $http service has its own caching layer, I didn't have to worry about an if/else. Not sure if this is idiomatic but it seems to work (boilerplate from angular-fullstack:service): This is an anti-pattern with promises, since you're just going to be left hanging if an error happens, your promise will never resolve. code:
Spraynard Kruger fucked around with this message at 15:52 on May 13, 2015 |
# ? May 13, 2015 15:47 |
|
Now I'm wholly confused. You guys were just telling me to use promises for this. I see that I'm not resolving in case of an $http error, but now you're telling me not to do the thing you just told me to do So…just farm out the $http call to a service that can cache the data…don't use promises?
|
# ? May 13, 2015 17:19 |
|
Dangerllama posted:I wound up consolidating it like so. Since the $http service has its own caching layer, I didn't have to worry about an if/else. Not sure if this is idiomatic but it seems to work (boilerplate from angular-fullstack:service): The other issue is you are relying entirely on the $http caching mechanism (which is fine if that's what you want). If you want to implement your own strategy (cache expires every 5 minutes, except on leap years when there is a blood moon), you will have to do it manually. Dangerllama posted:Now I'm wholly confused. You guys were just telling me to use promises for this. I see that I'm not resolving in case of an $http error, but now you're telling me not to do the thing you just told me to do You have to be using promises as $http is returning promises. If you are using $scope.cities = $http.get, Angular is automatically unwrapping that promise for you and making it look like $http.get actually returns a value. It doesn't, it returns a promise that should be handled. Using $q.when() like Spraynard suggested is probably the best way to do what you want. Skandranon fucked around with this message at 17:24 on May 13, 2015 |
# ? May 13, 2015 17:21 |
|
Alright, I'm going to go on a vision quest to figure this poo poo out.
|
# ? May 13, 2015 17:42 |
|
It helps if you think in terms of understanding the ES6 promise spec (this stuff is core JavaScript now) and treat the different libraries out there as implementation details. Here is some documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise You almost always want to use the foolproof way (new Promise) like this when wrapping/promisifying callback APIs manually: code:
|
# ? May 13, 2015 18:08 |
|
Stoph posted:Or even better, libraries like Bluebird add functions like Promise.promisify. Bluebird is one of a small handful of libraries that I consider essential for almost any project I work on, for anyone looking to get their feet wet with promises. Others being things like lodash, moment, numeral, etc. Speaking of, does anyone like a specific library for replacing jQuery's $.ajax and $.getJSON?
|
# ? May 14, 2015 04:09 |
|
Helicity posted:Speaking of, does anyone like a specific library for replacing jQuery's $.ajax and $.getJSON? I just started using it, but SuperAgent seems good so far.
|
# ? May 14, 2015 04:30 |
|
Helicity posted:Bluebird is one of a small handful of libraries that I consider essential for almost any project I work on, for anyone looking to get their feet wet with promises. Others being things like lodash, moment, numeral, etc.
|
# ? May 14, 2015 07:01 |
|
Helicity posted:Speaking of, does anyone like a specific library for replacing jQuery's $.ajax and $.getJSON?
|
# ? May 14, 2015 08:03 |
|
Helicity posted:Speaking of, does anyone like a specific library for replacing jQuery's $.ajax and $.getJSON? I've been using request.
|
# ? May 14, 2015 09:58 |
|
To be honest I've always found wrappers lacking in one way or another, whether its tracking progress, reliably parsing the body based on content type, not swallowing exceptions on a CORS error, I've always found something that shits me whether it's reqwests, jQuery, requests. I'd love to find a library that works but at this point xhr is actually trivial to write and well supported for modern dev, so I'd rather just do that and avoid the gaps in APIs. I dunno, I just never find it a big deal to write a comms wrapper for the app, that way even if you use a library it's trivial to swap it out.
|
# ? May 14, 2015 10:19 |
|
I rolled my own, because Mulaco's right. it's so easy you could tailor one to whatever your thought process is
|
# ? May 14, 2015 15:16 |
|
Helicity posted:Speaking of, does anyone like a specific library for replacing jQuery's $.ajax and $.getJSON? window.fetch is coming soon to browsers near you. There's a decent polyfill but it might be easier just to use XHR directly until all the dependencies (like window.Promise) are standard too.
|
# ? May 14, 2015 20:09 |
|
I've been out of this thread for a while and I'm wondering if there are any good tutorials for React/Flux that involve building a non-trivial example app.
|
# ? May 21, 2015 21:49 |
|
I remember following this: http://tech.pro/blog/2020/a-thrown-to-the-wolves-hands-on-introduction-to-react I found it more helpful to follow than some of the usual todo app examples.
|
# ? May 22, 2015 19:13 |
|
|
# ? Jun 7, 2024 17:57 |
|
yoyomama posted:I remember following this: http://tech.pro/blog/2020/a-thrown-to-the-wolves-hands-on-introduction-to-react This looks good thanks. When I learned Angular it was pretty easy to see the default structure for the various components but a lot of the React tutorials I've seen have the code right in the HTML file which can't be the right way to go. Also is jQuery the most common way to interact with backend services or are there better options?
|
# ? May 22, 2015 22:08 |