{"id":20674674,"url":"https://github.com/haxe-react/haxe-redux-thunk","last_synced_at":"2025-03-10T18:27:13.434Z","repository":{"id":57261851,"uuid":"124865457","full_name":"haxe-react/haxe-redux-thunk","owner":"haxe-react","description":"Redux thunk-like API for haxe-redux","archived":false,"fork":false,"pushed_at":"2018-09-27T18:49:28.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-21T15:17:29.654Z","etag":null,"topics":["haxe","redux"],"latest_commit_sha":null,"homepage":null,"language":"Haxe","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/haxe-react.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-12T09:33:14.000Z","updated_at":"2019-01-24T08:49:46.000Z","dependencies_parsed_at":"2022-08-25T06:11:00.610Z","dependency_job_id":null,"html_url":"https://github.com/haxe-react/haxe-redux-thunk","commit_stats":null,"previous_names":["klabz/haxe-redux-thunk"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haxe-react%2Fhaxe-redux-thunk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haxe-react%2Fhaxe-redux-thunk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haxe-react%2Fhaxe-redux-thunk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haxe-react%2Fhaxe-redux-thunk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haxe-react","download_url":"https://codeload.github.com/haxe-react/haxe-redux-thunk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242901479,"owners_count":20203949,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["haxe","redux"],"created_at":"2024-11-16T21:06:40.435Z","updated_at":"2025-03-10T18:27:13.390Z","avatar_url":"https://github.com/haxe-react.png","language":"Haxe","readme":"This feature has been merged in `haxe-redux`, and will be available starting next release (current version being `0.5.1`). It is already available using `haxelib git redux https://github.com/elsassph/haxe-redux`.\n\n# Haxe Redux Thunk\n\nRedux thunks (from [redux-thunk](https://github.com/gaearon/redux-thunk), more informations on thunks available [here](https://stackoverflow.com/questions/35411423/how-to-dispatch-a-redux-action-with-a-timeout/35415559#35415559)) are not really compatible with haxe-redux, since they work by dispatching functions instead of actions and catching them in a middleware.\n\nThis library reproduces this behavior, but with actual haxe-redux actions and a haxe-redux standard middleware.\nThis works by encapsulating your functions in an instance of the `redux.thunk.Thunk` enum.\n\nThere is no need for redux-thunk  runtime library, this is \"native\" haxe-redux code.\n\n## Usage\n\n### Installation\n\nUsing haxelib:\n`haxelib install redux-thunk`\n\n### Add middleware to your store\n\nYou have to add the `redux.thunk.ThunkMiddleware` for your thunks to be applied.\n\nWith haxe-redux way of using middlewares:\n```haxe\nvar middleware = Redux.applyMiddleware(\n\tmapMiddleware(Thunk, new ThunkMiddleware())\n\n\t// Or, if you want to add custom data like it is possible with redux-thunk:\n\t// mapMiddleware(Thunk, new ThunkMiddleware({custom: \"data\"}))\n\t// You can them consume this data with Thunk.WithParams (see below)\n);\n\ncreateStore(rootReducer, initialState, middleware);\n```\n\n### Create your thunks\n\nThe usual way of creating thunks is creating a dedicated class with public static functions returning `redux.thunk.Thunk` enum instances:\n```haxe\nclass TodoThunk {\n\tpublic static function add(todo:String) {\n\t\t// Encapsulate your thunk function in a `Thunk.Action` enum to create\n\t\t// an action recognized by `ThunkMiddleware`\n\t\t// Note that typing here is optional, but can help with autocompletion\n\t\t// and proper state typing\n\t\treturn Thunk.Action(function(dispatch:Dispatch, getState:Void-\u003eAppState) {\n\t\t\tvar todos = getState().todoList.todos;\n\n\t\t\tif (Lambda.exists(todos, function(t) return t.text == todo))\n\t\t\t\treturn null;\n\n\t\t\treturn dispatch(TodoAction.Add(todo));\n\t\t});\n\t}\n\n\tpublic static function dummy() {\n\t\t// Use `Thunk.WithParams` instead of `Thunk.Action` if you want to\n\t\t// consume the custom data from your thunk\n\t\treturn Thunk.WithParams(function(dispatch, getState, params) {\n\t\t\ttrace(params); // {custom: \"data\"}\n\t\t\treturn null;\n\t\t});\n\t}\n}\n```\n\n### Use your thunks in a container\n\nYou can use your thunks in the `mapDispatchToProps` function of your containers:\n```haxe\nstatic function mapDispatchToProps(dispatch:Dispatch) {\n\treturn {\n\t\taddTodo: function(todo:String) return dispatch(TodoThunk.add(todo))\n\t};\n}\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaxe-react%2Fhaxe-redux-thunk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaxe-react%2Fhaxe-redux-thunk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaxe-react%2Fhaxe-redux-thunk/lists"}