Skip to content

Commit

Permalink
Cleanup markdown sample code (#60)
Browse files Browse the repository at this point in the history
* fix markdown code snippets

* Use const/let in sample code

* run eslint on markdown code

* run eslint on markdown code
  • Loading branch information
Christopher Baker authored Feb 15, 2018
1 parent ca71c35 commit 5ceeea4
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 156 deletions.
130 changes: 65 additions & 65 deletions docs/can-define-stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@
The `can-define-stream` module exports a function that takes a [can-define-stream.types.streamInterface] and returns a function that takes a [can-define-stream.types.DefineMap DefineMap.prototype] or [can-define-stream.types.DefineList DefineList.prototype] and uses the supplied stream interface to create streamed property definitions.

```js
var canStream = require("can-stream-kefir");
var canDefineStream = require("can-define-stream");
var DefineMap = require("can-define/map/map");

var Person = DefineMap.extend({
first: "string",
last: "string",
fullName: {
get: function() {
return this.first + " " + this.last;
}
},
fullNameChangeCount: {
stream: function() {
return this.toStream(".fullName").scan(function(last) {
return last + 1;
}, 0);
}
}
});

canDefineStream(canStream)(Person);

var me = new Person({name: "Justin", last: "Meyer"});

me.on("fullNameChangeCount", function(ev, newVal) {
console.log(newVal);
});
me.fullNameChangeCount //-> 0
import canStream from "can-stream-kefir";
import canDefineStream from "can-define-stream";
import DefineMap from "can-define/map/map";

const Person = DefineMap.extend( {
first: "string",
last: "string",
fullName: {
get: function() {
return this.first + " " + this.last;
}
},
fullNameChangeCount: {
stream: function() {
return this.toStream( ".fullName" ).scan( function( last ) {
return last + 1;
}, 0 );
}
}
} );

canDefineStream( canStream )( Person );

const me = new Person( { name: "Justin", last: "Meyer" } );

me.on( "fullNameChangeCount", function( ev, newVal ) {
console.log( newVal );
} );
me.fullNameChangeCount; //-> 0
me.first = "Obaid"; //-> console.logs 1
me.last = "Ahmed"; //-> console.logs 2
```
Expand All @@ -56,36 +56,36 @@ me.last = "Ahmed"; //-> console.logs 2
The [can-define-stream.toStream] method has shorthands for all of the other methods:

```js
toStream("eventName") //-> stream
toStream(".propName") //-> stream
toStream(".propName eventName") //-> stream
toStream( "eventName" ); //-> stream
toStream( ".propName" ); //-> stream
toStream( ".propName eventName" ); //-> stream
```

For example:

__Update map property based on stream value__

```js
var DefineMap = require('can-define/map/map');
var canStream = require("can-stream-kefir");
var canDefineStream = require("can-define-stream");
import DefineMap from "can-define/map/map";
import canStream from "can-stream-kefir";
import canDefineStream from "can-define-stream";

var Person = DefineMap.extend({
name: "string",
lastValidName: {
stream: function() {
return this.toStream(".name").filter(function(name) { // using propName
return name.indexOf(" ") >= 0;
});
}
}
});
const Person = DefineMap.extend( {
name: "string",
lastValidName: {
stream: function() {
return this.toStream( ".name" ).filter( function( name ) { // using propName
return name.indexOf( " " ) >= 0;
} );
}
}
} );

canDefineStream(canStream)(Person);
canDefineStream( canStream )( Person );

var me = new Person({name: "James"});
const me = new Person( { name: "James" } );

me.on("lastValidName", function(lastValid) {});
me.on( "lastValidName", function( lastValid ) {} );

me.name = "JamesAtherton"; //lastValidName -> undefined
me.name = "James Atherton"; //lastValidName -> James Atherton
Expand All @@ -94,27 +94,27 @@ me.name = "James Atherton"; //lastValidName -> James Atherton
__Stream on DefineList__

```js
var DefineList = require('can-define/list/list');
var canStream = require("can-stream-kefir");
var canDefineStream = require("can-define-stream");
import DefineList from "can-define/list/list";
import canStream from "can-stream-kefir";
import canDefineStream from "can-define-stream";

var PeopleList = DefineList.extend({});
const PeopleList = DefineList.extend( {} );

canDefineStream(canStream)(PeopleList);
canDefineStream( canStream )( PeopleList );

var people = new PeopleList([
{ first: "Justin", last: "Meyer" },
{ first: "Paula", last: "Strozak" }
]);
const people = new PeopleList( [
{ first: "Justin", last: "Meyer" },
{ first: "Paula", last: "Strozak" }
] );

var stream = people.toStream('length'); // using eventName
const stream = people.toStream( "length" ); // using eventName

stream.onValue(function(val) {
val //-> 2, 3
});
stream.onValue( function( val ) {
val; //-> 2, 3
} );

people.push({
first: 'Obaid',
last: 'Ahmed'
}); //-> stream.onValue -> 3
people.push( {
first: "Obaid",
last: "Ahmed"
} ); //-> stream.onValue -> 3
```
40 changes: 20 additions & 20 deletions docs/methods.toStream.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
Creates a stream that gets updated whenever the property value changes or event is triggered.

```js
var DefineMap = require('can-define/map/map');
var canStream = require("can-stream-kefir");
var canDefineStream = require("can-define-stream");

var Person = DefineMap.extend({
name: "string",
lastValidName: {
stream: function() {
return this.toStream(".name").filter(function(name) { // using propName
return name.indexOf(" ") >= 0;
});
}
}
});

canDefineStream(canStream)(Person);

var me = new Person({name: "James"});

me.on("lastValidName", function(lastValid) {});
import DefineMap from "can-define/map/map";
import canStream from "can-stream-kefir";
import canDefineStream from "can-define-stream";

const Person = DefineMap.extend( {
name: "string",
lastValidName: {
stream: function() {
return this.toStream( ".name" ).filter( function( name ) { // using propName
return name.indexOf( " " ) >= 0;
} );
}
}
} );

canDefineStream( canStream )( Person );

const me = new Person( { name: "James" } );

me.on( "lastValidName", function( lastValid ) {} );

me.name = "JamesAtherton"; //lastValidName -> undefined
me.name = "James Atherton"; //lastValidName -> James Atherton
Expand Down
34 changes: 17 additions & 17 deletions docs/methods.toStreamFromEvent.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@
Creates a stream from an event that gets updated whenever the event is triggered.

```js
var DefineList = require('can-define/list/list');
var canStream = require("can-stream-kefir");
var canDefineStream = require("can-define-stream");
import DefineList from "can-define/list/list";
import canStream from "can-stream-kefir";
import canDefineStream from "can-define-stream";

var PeopleList = DefineList.extend({});
const PeopleList = DefineList.extend( {} );

canDefineStream(canStream)(PeopleList);
canDefineStream( canStream )( PeopleList );

var people = new PeopleList([
{ first: "Justin", last: "Meyer" },
{ first: "Paula", last: "Strozak" }
]);
const people = new PeopleList( [
{ first: "Justin", last: "Meyer" },
{ first: "Paula", last: "Strozak" }
] );

var stream = people.toStreamFromEvent('length'); // using eventName
const stream = people.toStreamFromEvent( "length" ); // using eventName

stream.onValue(function(val) {
val //-> 2, 3
});
stream.onValue( function( val ) {
val; //-> 2, 3
} );

people.push({
first: 'Obaid',
last: 'Ahmed'
}); //-> stream.onValue -> 3
people.push( {
first: "Obaid",
last: "Ahmed"
} ); //-> stream.onValue -> 3
```

@param {String} event An event name
Expand Down
40 changes: 20 additions & 20 deletions docs/methods.toStreamFromProperty.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
Creates a stream from a property that gets updated whenever the property value changes.

```js
var DefineMap = require('can-define/map/map');
var canStream = require("can-stream-kefir");
var canDefineStream = require("can-define-stream");

var Person = DefineMap.extend({
name: "string",
lastValidName: {
stream: function() {
return this.toStreamFromProperty(".name").filter(function(name) { // using propName
return name.indexOf(" ") >= 0;
});
}
}
});

canDefineStream(canStream)(Person);

var me = new Person({name: "James"});

me.on("lastValidName", function(lastValid) {});
import DefineMap from "can-define/map/map";
import canStream from "can-stream-kefir";
import canDefineStream from "can-define-stream";

const Person = DefineMap.extend( {
name: "string",
lastValidName: {
stream: function() {
return this.toStreamFromProperty( ".name" ).filter( function( name ) { // using propName
return name.indexOf( " " ) >= 0;
} );
}
}
} );

canDefineStream( canStream )( Person );

const me = new Person( { name: "James" } );

me.on( "lastValidName", function( lastValid ) {} );

me.name = "JamesAtherton"; //lastValidName -> undefined
me.name = "James Atherton"; //lastValidName -> James Atherton
Expand Down
22 changes: 11 additions & 11 deletions docs/types.DefineList.prototype.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
Creates a DefineList type instance

```js
import DefineMap from 'can-define/map/map';
import DefineList from 'can-define/list/list';
import DefineMap from "can-define/map/map";
import DefineList from "can-define/list/list";

var People = DefineList.extend([
'#': {
const People = DefineList.extend( {
"#": {
type: {
first: 'string',
last: 'string'
first: "string",
last: "string"
}
}
]);
} );

var people = new People([
{ first: 'John', last: 'Gardner' },
{ first: 'Justin', last: 'Meyer' }
])
const people = new People( [
{ first: "John", last: "Gardner" },
{ first: "Justin", last: "Meyer" }
] );
```

@body
Expand Down
18 changes: 9 additions & 9 deletions docs/types.DefineMap.prototype.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
Creates a DefineMap type instance

```js
import DefineMap from 'can-define/map/map';
import DefineMap from "can-define/map/map";

var Person = DefineMap.extend({
first: 'string',
last: 'string',
const Person = DefineMap.extend( {
first: "string",
last: "string",
fullName: {
get() {
return this.first + " " + this.last;
}
}
});
} );

var john = new Person({
first: 'John',
last: 'Gardner'
});
const john = new Person( {
first: "John",
last: "Gardner"
} );
```

@body
Expand Down
Loading

0 comments on commit 5ceeea4

Please sign in to comment.