All Projects → Luyakus → oc-redux

Luyakus / oc-redux

Licence: other
oc 版简易 redux 实现

Programming Languages

objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to oc-redux

Docketeer
An easy-to-use GUI for Docker that allows developers to manage Docker containers and monitor crucial metrics.
Stars: ✭ 431 (+1952.38%)
Mutual labels:  react-redux
react-ssr
从零搭建一个react-ssr框架 解决页面js事件 样式同构 服务器客户端路由 数据注水脱水等问题
Stars: ✭ 42 (+100%)
Mutual labels:  react-redux
ssr
React Server-Side Rendering Example
Stars: ✭ 265 (+1161.9%)
Mutual labels:  react-redux
React-Redux-Enterprise
A React-Redux boilerplate for enterprise/large scaled web applications
Stars: ✭ 77 (+266.67%)
Mutual labels:  react-redux
redux-analysis
《学习源码整体架构系列》多篇之redux源码,前端面试高频源码,微信搜索「若川视野」关注我,长期交流学习~
Stars: ✭ 28 (+33.33%)
Mutual labels:  react-redux
react-use-redux
Alternative Redux bindings with upcoming React hooks
Stars: ✭ 31 (+47.62%)
Mutual labels:  react-redux
react-mobile-starter
🌈 A starter project structure for React.js app using Dva.
Stars: ✭ 46 (+119.05%)
Mutual labels:  react-redux
energy-use-case-trading-client
Energy Use Case Web UI for Lition Trading Platform
Stars: ✭ 23 (+9.52%)
Mutual labels:  react-redux
book-fullstack-react
Fullstack React: The Complete Guide to ReactJS and Friends by Anthony Accomazzo
Stars: ✭ 100 (+376.19%)
Mutual labels:  react-redux
admin-template-for-react
🌏 Admin template for React, React Redux, Redux Saga, React Router, i18n and integrated OAuth login
Stars: ✭ 83 (+295.24%)
Mutual labels:  react-redux
react-redux-starter-kit
Get started with React, Redux, Webpack and eslint
Stars: ✭ 29 (+38.1%)
Mutual labels:  react-redux
isomorphic-react-redux-saga-ssr
Isomorphic, React, Redux, Saga, Server Side rendering, Hot Module Reloading, Ducks, Code Splitting
Stars: ✭ 19 (-9.52%)
Mutual labels:  react-redux
eshop
e-commerce website built with reactjs & redux on the frontend and lumen on the backend.
Stars: ✭ 27 (+28.57%)
Mutual labels:  react-redux
React-Native-Showcase
Best List of Open Source / Examples / Free / Case Study & Featured Template React Native Apps
Stars: ✭ 39 (+85.71%)
Mutual labels:  react-redux
Turbo-Browser
Simple & Secure Internet mobile browser built on React Native.
Stars: ✭ 25 (+19.05%)
Mutual labels:  react-redux
ReactCnodeJS
☀️React 初/中级项目,CnodeJS社区重构 (a junior project, rewrite cnodejs.org ) 🌟 DEMO:
Stars: ✭ 66 (+214.29%)
Mutual labels:  react-redux
Auxilium
Emergency reporting app.
Stars: ✭ 29 (+38.1%)
Mutual labels:  react-redux
boss
React+express+sock.io+mongodb build a boss
Stars: ✭ 25 (+19.05%)
Mutual labels:  react-redux
Color-Pic
Generate color palettes with image recognition
Stars: ✭ 21 (+0%)
Mutual labels:  react-redux
react-candee
A react framework that encapsulates the redux.
Stars: ✭ 30 (+42.86%)
Mutual labels:  react-redux

AHSRedux

AHSRedux 是 react-redux + thunk 的简易实现, 同时根据 iOS 平台的特点做了合理的精简

与 redux 相同的地方

  1. store, action, reducer, dispatcher, 基本元素一致
  2. 由 store 管理所有的 reducer
  3. 由 action 触发状态改变
  4. 由 diapatcher 分发 action

与 react-redux 不同的地方

由于 iOS 有天然的 controller, 所以我们只需要关心 controller 层级的状态共享即可, AHSRedux 相对于标准的 react-redux 有如下区别

  1. 隐式的 store, 使用者不需要手动创建 store, 也不需要 combineReducer, 一切都自然而然的发生
  2. 分散的 state, iOS controller 之间共享的状态可能仅仅是几个属性, 因此维持一个统一的 state 树显得非常的没有必要, 由相关的 reducer 管理
  3. 方便的 connect, 相较于 react-redux 中 connect 的弯弯绕, AHSRedux 的状态绑定显得非常直接, 一句话概括为, 谁请求, 谁处理, 谁需要, 谁订阅
  4. 天然的 thunk, AHSRedux 并没有中间件系统, 因此借助 ReactiveCocoa 将 thunk 整合了进来, 使用方式与其他 action 统一

示例

  1. 上传一段日志, 并监听状态
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor redColor];
    AHSRequestAction *action = [AHSRequestAction new];
    action.data = @"白日依山尽, 黄河入海流, 欲穷千里目, 更上一层楼";
    action.identifier = @"ahs://uploadlog";
    [self requestForUrl:@"ahs://uploadlog" action:action];
}

- (void)handleAction:(AHSDispatchSignalAction *)action {
    if ([action isKindOfClass:[AHSDispatchSignalAction class]] &&
        [action.identifier isEqualToString:@"ahs://uploadlog"]) {
        [action.signal subscribeNext:^(id x) {
            NSLog(@"上传中");
        } completed:^{
            NSLog(@"上传完成");
        }];
    }
}
  1. 注册 reducer, 订阅需要的信息或状态
@implementation AHSUploadLogReducer
+ (void)load {
    AHSUploadLogReducer *reducer = [AHSUploadLogReducer new];
    [reducer registForUrl:@"ahs://uploadlog"];
    [reducer registForUrl:@"ahs://otherurl"];
}

- (void)handleUrl:(NSString *)url requestAction:(AHSRequestAction *)action {
    if ([url isEqualToString:@"ahs://uploadlog"]) {
        NSLog(@"上传的日志为 %@", action.data);
        AHSDispatchSignalAction *progressAction = [AHSDispatchSignalAction new];
        progressAction.identifier = action.identifier;
        progressAction.signal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            [[[RACSignal interval:1 onScheduler:RACScheduler.mainThreadScheduler] take:10] subscribe:subscriber];
            return nil;
        }];
        ahs_redux_dispatch(progressAction);
        
        AHSDispatchDataAction *logAction = [AHSDispatchDataAction new];
        logAction.identifier = @"log_data";
        logAction.data = action.data;
        ahs_redux_dispatch(logAction);
    }
}

- (void)startWith:(NSString *)url {
    if ([url isEqualToString:@"ahs://uploadlog"]) {
        NSLog(@"init job for ahs://uploadlog");
    } else if ([url isEqualToString:@"ahs://otherurl"]) {
        NSLog(@"init job for ahs://otherurl");
    }
}
@end

@implementation AHSLogReducer
+ (void)load {
    AHSLogReducer *reducer = [AHSLogReducer new];
    [reducer registForUrl:@"ahs://nouserInterfaceinteraction"];
    [reducer registToReceiveActionForIdentifier:@"log_data"];
}

- (void)handleAction:(AHSDispatchDataAction *)action {
    if ([action isKindOfClass:[AHSDispatchDataAction class]]) {
        NSLog(@"log is %@", action.data);
    }
}
@end

写在最后

AHSRedux 是为了应对跨模块, 跨界面之间消息传递和状态共享的需求, 参考了前端的 react-redux, 根据 iOS 平台的特点实现的一个库. 是一层很薄的实现, 并没有限制做任何的扩展.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].