question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better syntax by removing .pipe()

See original GitHub issue

Is there any reason for using .pipe() to chain the actions? Chaining them directly would make more sense to me.

Current syntax

// Styles
gulp.task('styles', function() {
  return gulp.src('src/styles/main.scss')
    .pipe(sass({ style: 'expanded', }))
    .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
    .pipe(gulp.dest('dist/styles'))
    .pipe(rename({ suffix: '.min' }))
    .pipe(minifycss())
    .pipe(livereload(server))
    .pipe(gulp.dest('dist/styles'))
    .pipe(notify({ message: 'Styles task complete' }));
});

Proposed syntax

// Styles
gulp.task('styles', function() {
  return gulp.open('src/styles/main.scss') // open instead of gulp.src()
    .sass({ style: 'expanded', })
    .autoprefix() // verb instead of noun
    .save('dist/styles') // save instead of gulp.dest()
    .rename({ suffix: '.min' })
    .minifycss()
    .livereload(server)
    .save('dist/styles') // save instead of gulp.dest() 
    .notify({ message: 'Styles task complete' });
});

Does it make sense?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
phatedcommented, Jan 27, 2014

No, that is not how streams work. Please review the docs on stream basics.

0reactions
yocontracommented, Jan 28, 2014

If you really wanted this behavior you could write a library that loads stuff onto the Stream prototype like so

var Stream = require('stream');
var sass = require('gulp-sass');
var gulp = require('gulp');

var attach = function(name, fn){
  Stream.prototype[name] = function(){
    return this.pipe(fn.apply(fn, arguments));
  };
};

attach('open', gulp.src);
attach('save', gulp.dest);

// TODO: go through all installed gulp plugins and load them
// possibly use gulp-load-plugins for this
attach('sass', sass);

This would let you chain stuff

Read more comments on GitHub >

github_iconTop Results From Across the Web

Write Clean Python Code Using Pipes - Towards Data Science
Pipe is a Python library that enables you to use pipes in Python. A pipe ( | ) passes the results of one...
Read more >
Syntax checker incorrectly flags pipe operator after multiline ...
Describe the problem in detail. The following code generates the "unexpected token" warning. library(magrittr) "abc " %>% nchar().
Read more >
Removing NA in dplyr pipe [duplicate] - Stack Overflow
I used na.omit for all columns and it worked. outcome.df is a subset of large dataset. I'm trying to rank the conditions in...
Read more >
Transforming Data Using Pipes - Angular
Some pipes require at least one parameter and allow more optional parameters, such as SlicePipe . For example, {{ slice:1:5 }} creates a...
Read more >
Simplify Your Code with %>%
Removing duplication is an important principle to keep in mind with your code; ... by the magrittr package is %>% , or what's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found