tillrohrmann commented on a change in pull request #284: URL: https://github.com/apache/flink-statefun/pull/284#discussion_r791504850
########## File path: docs/content/docs/sdk/js.md ########## @@ -0,0 +1,267 @@ +--- +title: JavaScript +weight: 2 +type: docs +aliases: + - /sdk/js.html +--- +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +# JavaScript SDK + +Stateful functions are the building blocks of applications; they are atomic units of isolation, distribution, and persistence. +As objects, they encapsulate the state of a single entity (e.g., a specific user, device, or session) and encode its behavior. +Stateful functions can interact with each other, and external systems, through message passing. + +To get started, add the JavaScript SDK as a dependency to your application. + +{{< selectable >}} +``` +npm install apache-flink-statefun@{{< version >}} +``` +{{< /selectable >}} + +## Defining a Stateful Function + +A stateful function is any function that takes a `context` and `message` parameter. +In the following example, a `StatefulFunction` maintains a count for every user +of an application, emitting a customized greeting. + +```javascript +const {messageBuilder, StateFun, Context} = require("apache-flink-statefun"); + +let statefun = new StateFun(); + +statefun.bind({ + typename: "com.example.fns/greeter", + fn(context, message) { + const name = message.asString(); + let seen = storage.seen || 0; Review comment: ```suggestion let seen = context.storage.seen || 0; ``` ########## File path: docs/content/docs/sdk/js.md ########## @@ -0,0 +1,267 @@ +--- +title: JavaScript +weight: 2 +type: docs +aliases: + - /sdk/js.html +--- +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +# JavaScript SDK + +Stateful functions are the building blocks of applications; they are atomic units of isolation, distribution, and persistence. +As objects, they encapsulate the state of a single entity (e.g., a specific user, device, or session) and encode its behavior. +Stateful functions can interact with each other, and external systems, through message passing. + +To get started, add the JavaScript SDK as a dependency to your application. + +{{< selectable >}} +``` +npm install apache-flink-statefun@{{< version >}} +``` +{{< /selectable >}} + +## Defining a Stateful Function + +A stateful function is any function that takes a `context` and `message` parameter. +In the following example, a `StatefulFunction` maintains a count for every user +of an application, emitting a customized greeting. + +```javascript +const {messageBuilder, StateFun, Context} = require("apache-flink-statefun"); + +let statefun = new StateFun(); + +statefun.bind({ + typename: "com.example.fns/greeter", + fn(context, message) { + const name = message.asString(); + let seen = storage.seen || 0; + seen = seen + 1; + storage.seen = seen; Review comment: ```suggestion context.storage.seen = seen; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org