{"id":26022958,"url":"https://github.com/agrison/redux4j","last_synced_at":"2025-07-30T10:38:36.318Z","repository":{"id":57736571,"uuid":"71077929","full_name":"agrison/redux4j","owner":"agrison","description":"Java implementation of redux with Vavr","archived":false,"fork":false,"pushed_at":"2022-05-20T20:51:46.000Z","size":46,"stargazers_count":38,"open_issues_count":1,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-08-22T22:22:31.413Z","etag":null,"topics":["java","redux","vavr"],"latest_commit_sha":null,"homepage":"","language":"Java","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/agrison.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2016-10-16T21:21:22.000Z","updated_at":"2024-01-05T05:58:40.000Z","dependencies_parsed_at":"2022-08-24T03:01:08.482Z","dependency_job_id":null,"html_url":"https://github.com/agrison/redux4j","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agrison%2Fredux4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agrison%2Fredux4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agrison%2Fredux4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agrison%2Fredux4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agrison","download_url":"https://codeload.github.com/agrison/redux4j/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242194586,"owners_count":20087610,"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":["java","redux","vavr"],"created_at":"2025-03-06T10:37:35.940Z","updated_at":"2025-03-06T10:37:36.644Z","avatar_url":"https://github.com/agrison.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Redux in Java\n\n![redux4j](https://github.com/agrison/redux4j/workflows/build/badge.svg)\n[![codecov](https://codecov.io/gh/agrison/redux4j/branch/master/graph/badge.svg?token=lkICxLZmij)](https://codecov.io/gh/agrison/redux4j)\n\nUsing Java and Vavr.\n\n## Features\n\n* Store\n* Reducer\n* CombineReducers\n* Middlewares\n\n## Install\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eme.grison\u003c/groupId\u003e\n  \u003cartifactId\u003eredux4j\u003c/artifactId\u003e\n  \u003cversion\u003e1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Counter example\n\n```java\npublic class Counter {\n    // Actions\n    static final String INC = \"INC\";\n    static final String DEC = \"DEC\";\n\n    // this is our reducer which increments if INC, decrement if DEC\n    // and does nothing otherwise\n    final Reducer\u003cString, Integer\u003e reducer =\n            (action, state) -\u003e state + switch (action) {\n                case INC -\u003e 1;\n                case DEC -\u003e -1;\n                default -\u003e 0;\n            };\n\n    public void foo() {\n        // This is our store with its initial state of zero and the reducer seen above\n        Store\u003cInteger, String\u003e store = Redux.createStore(0, reducer);\n\n        // dispatch an INC action\n        store.dispatch(INC);\n        store.getState(); // 1\n\n        // dispatch an DEC action\n        store.dispatch(DEC);\n        store.getState(); // 0\n    }\n}\n```\n\n## Middlewares\n\n```java\npublic class Counter {\n\n    final Middleware\u003cInteger, String\u003e middleware = (store, action, next) -\u003e {\n        System.out.println(\"Before \" + store.getState());\n        next.accept(store, action, null);\n        System.out.println(\"After \" + store.getState());\n    };\n\n    public void foo() {\n        Store\u003cInteger, String\u003e store = Redux.createStore(0, reducer, middleware);\n\n        store.dispatch(INC);\n    }\n}\n```\n\nOutputs:\n\n    Before 0\n    After 1\n\n## Combine Reducers\n\n```java\npublic class Foo {\n\tReducer\u003cString, String\u003e concatBar =\n\t\t\t(action, state) -\u003e \"CONCAT\".equals(action) ? state + \"bar\" : state;\n\n\tReducer\u003cString, Integer\u003e plus2 =\n\t\t\t(action, state) -\u003e \"PLUS\".equals(action) ? state + 2 : state;\n\n\tReducer\u003cString, List\u003cString\u003e\u003e addFoo = (action, state) -\u003e {\n\t\t\t\t\tif (\"ADD\".equals(action))\n\t\t\t\t\t\tstate.add(\"foo\");\n\t\t\t\t\treturn state;\n\t\t\t\t};\n\n\tReducer reducers = Redux.combineReducers(Tuple.of(\"str\", concatBar), Tuple.of(\"int\", plus2), Tuple.of(\"list\", addFoo));\n\n\t@Test\n\tpublic void testCombineReducersMap() {\n\t\tMap\u003cString, Object\u003e initialState = new HashMap\u003cString, Object\u003e() {{\n\t\t\tput(\"str\", \"foo\");\n\t\t\tput(\"int\", 1);\n\t\t\tput(\"list\", new ArrayList\u003cString\u003e());\n\t\t}};\n\t\tStore\u003cMap\u003cString,Object\u003e, String\u003e store = Redux.createStore(initialState, reducers);\n\n\t\tassertThat(store.getState().get(\"str\"), equalTo(\"foo\"));\n\t\tstore.dispatch(\"CONCAT\");\n\t\tassertThat(store.getState().get(\"str\"), equalTo(\"foobar\"));\n\n\t\tassertThat(store.getState().get(\"int\"), equalTo(1));\n\t\tstore.dispatch(\"PLUS\");\n\t\tassertThat(store.getState().get(\"int\"), equalTo(3));\n\t\tstore.dispatch(\"PLUS\");\n\t\tassertThat(store.getState().get(\"int\"), equalTo(5));\n\n\t\tstore.dispatch(\"CONCAT\");\n\t\tassertThat(store.getState().get(\"str\"), equalTo(\"foobarbar\"));\n\n\t\tassertThat(store.getState().get(\"list\"), equalTo(Arrays.asList()));\n\t\tstore.dispatch(\"ADD\");\n\t\tassertThat(store.getState().get(\"list\"), equalTo(Arrays.asList(\"foo\")));\n\t\tstore.dispatch(\"ADD\");\n\t\tassertThat(store.getState().get(\"list\"), equalTo(Arrays.asList(\"foo\", \"foo\")));\n\t}\n\n\t// same with a javabean with getters/setters\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagrison%2Fredux4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagrison%2Fredux4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagrison%2Fredux4j/lists"}